How to deal with dropdowns / selectgroups in Selenium ?

  • 1 Replies
  • 1140 Views
How to deal with dropdowns / selectgroups in Selenium ?
« on: March 09, 2016, 14:03:34 pm »
What is the best way to iterate over and select items from a dropdown / selectgroup with selenium ?

Oftentimes i'm struggling to get data from dropdown items and performing basic operations are exhaustive.

*

Oren

  • **
  • 59
Re: How to deal with dropdowns / selectgroups in Selenium ?
« Reply #1 on: March 09, 2016, 17:53:54 pm »
Basically you would want to work with dropdowns as select elements instead of WebElements. If you are working with Java, there are enough methods that allow you to automate and trigger common tasks.

For example :

Code
WebElement selectElement = driver.findElement(By.id("id")); 
Select select= new Select(selectElement);
select.selectByValue("value");

There are other ways to play around with dropdowns and selectgroups with css selectors and xpath, but the easiest way would be with select class.

 

Sitemap 1 2 3 4 5 6 7 8