Webdriverjs apparently has an inbuilt method which allows you to wait for an element.
var saveButton = driver.wait(until.elementLocated(By.xpath("//div[text() = 'Save']")), 5000);
driver.wait(until.elementIsVisible(saveButton), 5000).click();
Using this method results in an error "ReferenceError: until is not defined". Why is this method not working?
Explicit Wait in Selenium By using the Explicit Wait command, the WebDriver is directed to wait until a certain condition occurs before proceeding with executing the code. Setting Explicit Wait is important in cases where there are certain elements that naturally take more time to load.
Using Implicit Wait If the tester knows how much time the page and element will take to load, they should use Implicit Wait. Let's say a website under test takes ten seconds to load a page until a particular element shows up. In that case, set implicit wait for 10 seconds.
Default value of implicit wait is 0 seconds. This means that WebDriver will try to find the element only once and after that it will throw an exception if element is not found. Implicit wait has a default polling time of 250 milliseconds.
Selenium Webdriver provides two types of waits - implicit & explicit. An explicit wait makes WebDriver wait for a certain condition to occur before proceeding further with execution. An implicit wait makes WebDriver poll the DOM for a certain amount of time when trying to locate an element.
The most common best practice is to require webdriver.By
and webdriver.until
at the top of your file right after you require webdriver.
then you don't have to do webdriver.By
inside your tests, you can do driver(By.css())
I read the webdriverjs docs and the example given there is missing 'webdriver' keyword.
var saveButton = driver.wait(webdriver.until.elementLocated(webdriver.By.xpath("//div[text() = 'Save']")), 5000);
driver.wait(until.elementIsVisible(saveButton), 5000).click();
Adding 'webdriver' keyword before 'until' and 'By' solves the issue.
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