Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent code of selenium.waitForPageToLoad("30000") in Selenium WebDriver?

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?

like image 497
Ripon Al Wasim Avatar asked Aug 22 '13 10:08

Ripon Al Wasim


People also ask

What happens if WaitFor is failed in Selenium?

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.

What is pageLoadTimeout in Selenium?

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.

What is WaitFor in Selenium?

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.


1 Answers

2 approaches:

  1. If you need to wait exactly 60 sec you could use Thread.sleep(60000)

  2. 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.

like image 75
praneel Avatar answered Sep 22 '22 00:09

praneel