0 votes
1 view
in Devops and Agile by (19.8k points)

I am writing some Java Webdriver code to automate my application. How can I correctly check whether the page has been loaded or not? The application has some Ajax calls, too.

I have declared an implicit wait for WebDriver.

1 Answer

0 votes
by (63.4k points)

Selenium does it for you. Or at least it tries its best. The usual solution is Implicit Wait which solves most of your problems.

If you really know what you're doing, and why you're doing it, you could try to write a generic method that would check whether the page is completely loaded. However, it can't be done for every web and for every situation.

The "normal" load is easy using document.readyState. This one is implemented by Selenium, of course. The problematic thing is asynchronous requests, AJAX, because you can never tell whether it's done for good or not. Most of today's web pages have scripts that run forever and poll the server all the time.

One thing that will be helpful is you use Implicit Wait implicitly and Explicit Wait + ExpectedConditions where needed.

E.g. after a click, some element on the page should become visible and you need to wait for it:

WebDriverWait wait = new WebDriverWait(driver, 10);  

// you can reuse this one

WebElement elem = driver.findElement(By.id("InvisibleElement"));

elem.click();

wait.until(ExpectedConditions.visibilityOf(elem));

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...