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!