Home >Java >javaTutorial >How to Reliably Wait for Page Load in Selenium?

How to Reliably Wait for Page Load in Selenium?

Barbara Streisand
Barbara StreisandOriginal
2024-12-17 10:04:25502browse

How to Reliably Wait for Page Load in Selenium?

Waiting for Page Load in Selenium

In Selenium, waiting for a page to load is crucial for reliable automation. There are various techniques to accomplish this.

Selenium 2.0 Wait

WebDriverWait, introduced in Selenium 2.0, is a flexible option for waiting. Use it as follows:

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(30));
wait.until(driver1 -> ((JavascriptExecutor) driver1).executeScript("return document.readyState").equals("complete"));

This method waits for 30 seconds until the document's readyState property becomes "complete," indicating that the page has loaded.

The above is the detailed content of How to Reliably Wait for Page Load in Selenium?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn