0 votes
1 view
in Devops and Agile by (19.8k points)

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


1 Answer

0 votes
by (63.4k points)
selected by
Best answer

Take a glance at the section regarding filling in forms using web driver within the Selenium documentation and also 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")));



 To get the first selected value:

WebElement option = select.getFirstSelectedOption();

Hope this helps! 

Welcome to Intellipaat Community. Get your technical queries answered by top developers !