Pawan Juyal
Pawan Juyal

Reputation: 261

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?

Upvotes: 6

Views: 5350

Answers (3)

codemon
codemon

Reputation: 1594

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

Upvotes: 9

Pawan Juyal
Pawan Juyal

Reputation: 261

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.

Upvotes: 9

undetected Selenium
undetected Selenium

Reputation: 193078

I am not sure the language binding you are using. Using Java bindings, in Selenium 3.x releases until must be accompanied by ExpectedConditions

So, to apply ExplicitWait on an element & click it, your code must look like:

    WebDriverWait wait = new WebDriverWait(driver, 5);
    WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[text() = 'Save']"))); 
    element.click();

Let me know if this solves your Question.

Upvotes: 0

Related Questions