Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why using inbuilt webdriver wait yields an error "ReferenceError: until is not defined"?

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?

like image 536
Pawan Juyal Avatar asked May 01 '17 06:05

Pawan Juyal


People also ask

Which wait makes WebDriver wait for a certain condition to occur before proceeding further with execution?

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.

Which wait statement will be used to wait till page 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.

What is the default value for WebDriver implicit wait?

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.

What is WebDriver wait in selenium?

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.


2 Answers

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())

like image 55
codemon Avatar answered Oct 22 '22 16:10

codemon


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.

like image 43
Pawan Juyal Avatar answered Oct 22 '22 15:10

Pawan Juyal