Unable To Select From Ui Li Elements In Selenium Java
I am Automating add to card process of 'http://www.fnp.com/the-sweet-surprises-genpr-143431-e.html' website. I am writing a code Using TestNG  Structure . I got Stuck in task where
Solution 1:
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get("http://www.fnp.com/the-sweet-surprises-genpr-143431-e.html");
driver.findElement(By.id("tagsf2")).sendKeys("Gandhinagar");
/*The below three line code is to select the option "Gandhinagar " from the drop down box for City name */
WebElement selectShippingModeInput =    driver.findElement(By.id("ddShipingModep1_input"));
selectShippingModeInput.click();     
selectShippingModeInput =    driver.findElement(By.id("ddShipingModep1_input"));
selectShippingModeInput.click(); 
/* The below code fetches all the options from the drop down box for "Shipping option"*/
List<WebElement>     options=driver.findElements(By.xpath("//div[@id='ddShipingModep1_container']/ul/li"));
for(WebElement option:options){
/*The below code fetches the text of the drop down items */
String name=option.getText();
/The below two line code is to focus on the select box/
   selectShippingModeInput = driver.findElement(By.id("ddShipingModep1_input"));     
   selectShippingModeInput.click(); 
/*The drop down item "Standard Delivery [Rs. 0] is selected from the drop down box */
if(name.equals("Standard Delivery [ Rs. 0 ]")){
               selectShippingModeInput.click();
               option.click();
               break;
                                            }
                       }
Solution 2:
You have to click the <input id="ddShipingModep1_input" twice, then the options will be displayed. See code below:
...
WebElementselectShippingModeInput= driver.findElement(By.id("ddShipingModep1_input"));
selectShippingModeInput.click();        
selectShippingModeInput = driver.findElement(By.id("ddShipingModep1_input"));
selectShippingModeInput.click();
try {
    Thread.sleep(1000);
} catch (InterruptedException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
List<WebElement> allElements = driver.findElements(By.xpath("//div[@id='ddShipingModep1_container']/ul/li"));
...
Post a Comment for "Unable To Select From Ui Li Elements In Selenium Java"