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"));
.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