WaitForCondition does not work, but Thread.sleep does the script work

When using the application Thread.sleep(2000) works well, but on waitForCondition it fails. Is there a better way to use the waitForCondition function? Please provide some examples. Can we give //h1[@class='some'] in waitForCondition ? or waitForCondition work on a specific path?

I used like:

 selenium.waitForCondition("selenium.isElementPresent(\"//div[@id='pagging-section']\")","5000"); 

But it fails. Thread.sleep works well, but I am not recommended to use this method.

Please share with me the correct use of waitForCondition and any other best way to wait and find the item and continue.

+4
source share
1 answer

There may be a delay between when selenium thinks the page is loaded and is actually loading. Basically, I had the same problem.

I wrote my own small structure to handle this situation: when checking the conditions, I had a loop with Thread.sleep(200) , which caught any β€œnot found” exceptions and gave up after a timeout (I used 20 seconds), and it works great.

Use Thread.sleep()

+1
source

All Articles