質問

I tried to use ExplicitWait for an autosuggest box but it did not work, so I am using simple Thread.sleep(5000):

/***************************************************************************************/ 
                                // The below Thread.sleep(5000) works fine 
                        //                    Thread.sleep(5000); 

        // However the below Explicit Wait block does not recognize the element
                        WebDriverWait wait5000 = new WebDriverWait(driver, 0);
                        wait5000.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@class='auto_suggest']/*[@class='title_item']")));
    /***************************************************************************************/    


                        WebElement firstItem = driver.findElement(By.xpath("//*[@class='auto_suggest']/*[@class='title_item']"));
                        firstItem.click();
                          System.out.println("Done!");

                }

            }

I can use Thread.sleep(5000) but this is not efficient, because of time loss. Is there any way to introduce an explicit wait for the autosuggest box? How to click the autosuggest box more in a more efficient way?

役に立ちましたか?

解決

The 2nd parameter in the constructor is the timeout in milliseconds.

Here WebDriverWait wait5000 = new WebDriverWait(driver, 0); you are passing in 0 - you are giving it a maximum of 0 milliseconds to find the element. You could try increasing the timeout, for example, let it search for the element for up to 5 whole seconds:

WebDriverWait wait5000 = new WebDriverWait(driver, 5000);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top