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

How to Reliably Wait for Page Load in Selenium?

Barbara Streisand
Release: 2024-12-17 10:04:25
Original
507 people have browsed it

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"));
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template