6

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?

Pawan Juyal
  • 251
  • 1
  • 5
  • 14

3 Answers3

9

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.

Pawan Juyal
  • 251
  • 1
  • 5
  • 14
9

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

codemon
  • 1,456
  • 1
  • 14
  • 26
0

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.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352