The following is the java code to wait for a page loading in Selenium RC:
selenium.waitForPageToLoad("30000");
What is the equivalent java code in Selenium WebDriver?
When a “verify” fails, the test will continue execution, logging the failure. A “waitFor” command waits for some condition to become true. They will fail and halt the test if the condition does not become true within the current timeout setting. Perhaps, they will succeed immediately if the condition is already true.
The pageLoadTimeout is the method used to set the time for the entire page load prior to throwing an exception. If the timeout time is set to negative, then the time taken to load the page is endless. This timeout is generally used with the navigate and manage methods.
WaitFor commands are not hard waits; meaning that they will, by default, wait up to 30 seconds to find an element, but if they find an element before 30 seconds, they continue without waiting the remainder of the time.
2 approaches:
If you need to wait exactly 60 sec you could use Thread.sleep(60000)
If you want to make sure that the page is loaded (it could be less than or greater than 60 sec) I would recommend the below approach:
Identify an element in the landing page & wait for it to be clickable. You are then sure that the page has been loaded.
WebDriverWait wait = new WebDriverWait(driver,120);
wait.until(ExpectedConditions.elementToBeClickable(By.id(id)));
WebDriver waits for a max of 120 sec. for the element to be clickable. If the element is clickable before that, your test would progress.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With