0 votes
1 view
in DevOps and Agile by (20k points)

If I want to select an option of a dropdown box, there are several ways to do that. I always used:


But that didn't work every time. Sometimes another option was selected. So I googled a little bit and found this piece of code which works every time:

WebElement select = driver.findElement(By.id("selection"));

    List<WebElement> options = select.findElements(By.tagName("option"));

    for (WebElement option : options) {




But that works really really slow. If I have a long list with many items in it, it really takes too much time. So my question is, is there a solution which works every time and is fast?

1 Answer

0 votes
by (28.4k points)

This chunk of code should do the magic: 

import org.openqa.selenium.support.ui.Select;

Select droplist = new Select(driver.findElement(By.Id("selection")));   


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