What's the best way to wait for a page to fully load using selenium-webdriver for javascript? I noticed this question is quite similar but I need an implementation in javascript.
var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;
var driver = new webdriver.Builder()
.forBrowser('firefox')
.build();
driver.get('http://www.google.com');
// Wait for the page to fully load here...
// Something like this...
// driver.wait(...);
// Then do other stuff here
driver.quit();
We can wait until the page is completely loaded in Selenium webdriver by using the JavaScript Executor. Selenium can run JavaScript commands with the help of the executeScript method. We have to pass return document.
For Python, you will have to implement Selenium Wait for page to load in order to ensure that tests are performed with the necessary WebElements in the DOM. Certain websites have some components or elements hidden, or not visible at an initial stage.
PageLoadTimeout Command This command establishes the time WebDriver must wait for a page to completely load before triggering an error. In case the timeout set is negative, the page load time can be indefinite.
I found that this works for what I needed.
driver.get('http://www.google.com');
driver.wait(function() {
return driver.executeScript('return document.readyState').then(function(readyState) {
return readyState === 'complete';
});
});
// Do stuff after page load here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With