3044/wait-for-page-to-load-using-htmlunitdriver
I use HTML driver and when I run the tests and want to click on an element or read text, the elements can not be found. Every time a Exception is thrown I have to save the code of the Page.When I check the Code, the element is there and when I re run the test everything works fine. My guess is that the page was not completely loaded when I try to access the element. So I wait until Selenium has finished loading the page before I try to access elements.
I found two ways to achieve it:
Execute Javascript (e.g. window.initComplete) and wait for the result to be true.
Wait for the last element on the page to load
Any suggestions ?
You can create a custom ExpectedCondition
public static ExpectedCondition<Boolean> waitForLoad() {
return new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
return ((JavascriptExecutor) driver).executeScript("return document.readyState").equals("done");
}
};
}
Firstly, when you launch a web application, ...READ MORE
You can try out the below code:
...READ MORE
you need to wait for Javascript and ...READ MORE
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds below code.
Select sc = new Select(driver.findElement(By.xpath("your ...READ MORE
When we try to test the presence ...READ MORE
OR
Already have an account? Sign in.