如何在Selenium web Driver中写入等待,直到值填充下拉,然后单击按钮

Hum*_*uma 2 java selenium

在我的应用程序中,当我打开一个页面时,会显示一个下拉列表,然后我需要单击一个继续按钮.问题是下拉需要一些时间来加载值,但在我的代码中,它在下拉加载之前单击.我尝试使用隐式wait和thread.sleep但它有时候它工作,有些时候不起作用.码:

       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("webdriver.ie.driver", file1.getAbsolutePath());

   WebDriver driver = new InternetExplorerDriver();
    driver.get("http://10.120.13.100/");

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

    Thread.sleep(3000);

    WebElement clickBtn = driver.findElement(By.id("btnHomeProceed"));
   clickBtn.click(); 
Run Code Online (Sandbox Code Playgroud)

xyz*_*xyz 5

您可以使用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());
            }
        });
Run Code Online (Sandbox Code Playgroud)