Huma Huma - 4 months ago 30
Java Question

How to write wait in Selenium web Driver until values get filled in drop down and then click on a button

In my application when i opens a page a dropdown displays and then i need to click on a proceed button. Problem is drop down takes some time to load the values but in my code it click before the drop down loads.I tried with implicit wait and thread.sleep but it some time it work and some time doesn't work.

public class Home {

public static void main(String[] args) throws IOException, InterruptedException
File file1 = new File("C:\\Selenium\\IEDriverServer_Win32_2.35.3\\IEDriverServer.exe");
System.setProperty("", file1.getAbsolutePath());

WebDriver driver = new InternetExplorerDriver();

driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);


WebElement clickBtn = driver.findElement("btnHomeProceed"));;

xyz xyz

You can use FluentWait

final Select droplist = new Select(driver.findElement(By.Id("selection")));
new FluentWait<WebDriver>(driver)
        .withTimeout(60, TimeUnit.SECONDS)
        .pollingEvery(10, TimeUnit.MILLISECONDS)
        .until(new Predicate<WebDriver>() {

            public boolean apply(WebDriver d) {
                return (!droplist.getOptions().isEmpty());