How to select/get drop down option in Selenium 2

0
0

I am converting my selenium 1 code to selenium 2 and can’t find any easy way to select a label in a drop down menu or get the selected value of a drop down. Do you know how to do that in Selenium 2?

Here are two statements that work in Selenium 1 but not in 2:

browser.select("//path_to_drop_down", "Value1");
browser
.getSelectedValue("//path_to_drop_down");
  • You must to post comments
0
0

Take a look at the section about filling in forms using webdriver in the selenium documentation and the javadoc for the Select class.

To select an option based on the label:

Select select = new Select(driver.findElement(By.xpath("//path_to_drop_down")));
select
.deselectAll();
select
.selectByVisibleText("Value1");

To get the first selected value:

WebElement option = select.getFirstSelectedOption()
  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website