How can I get Dropdown values using Selenium(Webdriver)

5,228 views
Skip to first unread message

Binken

unread,
Aug 20, 2010, 1:57:29 AM8/20/10
to Selenium Users
How can I get Dropdown values using Selenium(Webdriver)

Bindu Laxminarayan

unread,
Aug 20, 2010, 5:29:59 PM8/20/10
to Selenium Users
With IDE: identify the select element, call the storeText method and
echo the values.
With RC: identify the select element and call getText method and
display the values or call substring function to break the string to
various options.

Example, you can find on : http://www.hexbytes.com/category/automation/selenium/faq/

Thanks
Bindu Laxminarayan

Sergey Pozharov

unread,
Aug 25, 2010, 4:59:40 AM8/25/10
to seleniu...@googlegroups.com
You can use org.openqa.selenium.support.ui.Select class:

Select dropDown = new Select(driver.findElement(By...));
List<WebElement> options = dropDown.getOptions();

Or you can do it directly:

WebElement dropDown1 = driver.findElement(By...);
List<WebElement> options = dropDown.findElements(By.tagName("option"));

Then you can iterate through options to get value or text:

for (WebElement el : options) {
System.out.println(el.getValue());
}

On Fri, Aug 20, 2010 at 8:57 AM, Binken <binke...@gmail.com> wrote:
> How can I get Dropdown values using Selenium(Webdriver)
>

> --
> You received this message because you are subscribed to the Google Groups "Selenium Users" group.
> To post to this group, send email to seleniu...@googlegroups.com.
> To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages