How can I get all elements from a drop down list? I used the code below:
List elements = driver.findElements(By.id(\"s\"));
There is a class designed for this in the bindigs.
You are looking for the Select
class:
https://code.google.com/p/selenium/source/browse/java/client/src/org/openqa/selenium/support/ui/Select.java
You would need to 'find' the actual select
element, not the individual options. Find that select
element, and let Selenium & the Select
class do the rest of the work for you.
You'd be looking for something like (s
being the actual select
element):
WebElement selectElement = driver.findElement(By.id("s");
Select select = new Select(selectElement);
The Select
class has a handy getOptions()
method. This will do exactly what you think it does.
List allOptions = select.getOptions();
Now you can do what you want with allOptions
.