Friday, March 27, 2015

There are two methods out of which first one is preferrable:

Method1:

First you have to get the Select element of the dropdown using below statement
Select dropdown = new Select(
new WebDriverWait(driver, 10).until(ExpectedConditions
.presenceOfElementLocated(By.id("elementid"))));


Then using the Select element you get, you can select the dropdown value by using any of the below statement


dropdown.selectByVisibleText("dropdownvalue");
or
dropdown.selectByIndex(0);
or
dropdown.selectByValue("value");


Method2:

List<WebElement> dd= new ArrayList<WebElement>();
dd = new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.id("elementid")))
.findElements(By.tagName("option"));
for (WebElement option : dd) {
//System.out.println(option.getText());
if (outname.equalsIgnoreCase(option.getText())){
option.click();
break;
}
}

Method 1 is more preferrable in Selenium webdriver. However in PhantomJS I found first method is not working. So try method 2 in such cases.

0 comments:

Post a Comment

>

Selenium useful links

Powered by Blogger.

Featured Post

Benefits of having a user Interface for a Selenium Automation Suite/Regression Suite

Once you are able to work independently on Selenium scripting, another important task is how to ease your automation test execution. There a...

Video

Popular Posts

Our Facebook Page