How to use the until function from selenium-webdriver

Find comprehensive JavaScript selenium-webdriver.until code examples handpicked from public code repositorys.

selenium-webdriver.until is a module that provides a set of functions to wait for a certain condition to occur before continuing the execution of the automation script.

9
10
11
12
13
14
15
16
17
18
const promise = require('selenium-webdriver/lib/promise')
const chromedriver = require('chromedriver')
const log = require('npmlog')

// shortcuts
const until = webdriver.until
const By = webdriver.By

/* -----------------------------------------------------------------------------
 * configure
fork icon26
star icon428
watch icon3

84
85
86
87
88
89
90
91
92
93
```javascript
//To initate our tests, we must first include the selenium-webdriver module. We require the module and assign it to the variable "webdriver". We create a "By" and "until" shorthand variable for referencing the "By" class and "until" module more easily within our subsequent code. "until" defines common conditions for use with "WebDriver wait". "By" describes a mechanism for locating an element on the page.

var webdriver = require('selenium-webdriver'),
    By = webdriver.By,
    until = webdriver.until;

var driver_fx = new webdriver.Builder()
    .forBrowser('firefox')
    .build();
fork icon114
star icon102
watch icon22

How does selenium-webdriver.until work?

selenium-webdriver.until is a module that provides a collection of expected conditions that can be used to wait for specific conditions to be met in a web application, such as the presence of an element or its visibility. It allows you to perform asynchronous actions and wait for them to complete before moving on to the next step of your script. These conditions can be used with the WebDriver instance to wait for the required state of the application. The module provides different expected conditions to choose from and allows you to define custom conditions as well.

256
257
258
259
260
261
262
263
264
265
    });
  });

  Then('I should see {stringInDoubleQuotes}', function (text) {
    var xpath = "//*[contains(text(),'" + text + "')]";
    var condition = seleniumWebdriver.until.elementLocated({xpath: xpath});
    return this.driver.wait(condition, 5000);
  });
});
```
fork icon34
star icon313
watch icon14

7
8
9
10
11
12
13
14
15
16
//simplify webdriver usage
global.by = webdriver.By;
global.key = webdriver.Key;
global.promise = webdriver.promise;
global.bot = webdriver.error;
global.until = webdriver.until;

module.exports = fiveby;

function fiveby(config) {
fork icon8
star icon134
watch icon14

+ 3 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
const { Builder, By, until } = require("selenium-webdriver");

(async function example() {
  let driver = await new Builder().forBrowser("chrome").build();
  try {
    await driver.get("https://www.example.com");
    let element = await driver.findElement(By.name("q"));
    await driver.wait(until.elementIsVisible(element), 10000);
    await element.sendKeys("webdriver");
    await element.submit();
  } finally {
    await driver.quit();
  }
})();

In this example, the driver.wait method is used in conjunction with until.elementIsVisible to wait for the element with the name "q" to be visible before sending keys to it and submitting the form.

17
18
19
20
21
22
23
24
25
26
 * An utility with the specifics for selenium
 */
const phantomjs = require('phantomjs-prebuilt');
const webdriver = require('selenium-webdriver');
const By = webdriver.By;
const until = webdriver.until;

const driver = new webdriver.Builder()
  .withCapabilities({'phantomjs.binary.path': phantomjs.path})
  .forBrowser('phantomjs')
fork icon395
star icon0
watch icon2

137
138
139
140
141
142
143
144
145
146
/**
 * @param func {function|WebElement}
 */
function wait(func, errMsg, timeout) {
        if (_.isFunction(func))
                return driver.wait(new webdriver.until.Condition(errMsg || 'wait() timeout', func),
                        timeout || WAIT_TIMEOUT,
                        errMsg || 'wait() timeout');
        else {
                return waitForElement(func, errMsg, timeout);
fork icon3
star icon0
watch icon1

+ 5 other calls in file

18
19
20
21
22
23
24
25
26
27
var webdriverRemote = require('selenium-webdriver/remote');
var sprintf = require('sprintf-js').sprintf;
var config = require('./config.js');
var pageUrlData = require(global.tf.projectDir + '/data/pageUrlData.js');
var fs = require('fs');
var until = webdriver.until;

//vars
var driver;
var logsDirName;
fork icon2
star icon0
watch icon1

9
10
11
12
13
14
15
16
17
18

if (!world) {
  throw new Error('World must be defined')
}

until = until || webDriver.until
_.extend(until, {
  foundInPage: (selector) => new webDriver.Condition(`for $("${selector}") to be found in page`, co(function * (selector) {
    const driver = yield world.getDriver()
    return yield driver.findElement(By.css(selector))
fork icon1
star icon3
watch icon3

24
25
26
27
28
29
30
31
32
33
this.WebElement = webdriver.WebElement;
this.WebElementPromise = webdriver.WebElementPromise;
this.error = webdriver.error;
this.logging = webdriver.logging;
this.promise = webdriver.promise;
this.until = webdriver.until;
this.Command = require('selenium-webdriver/lib/command').Command;
this.CommandName = require('selenium-webdriver/lib/command').Name;
this.utils = {
    firefox: require('selenium-webdriver/firefox'),
fork icon1
star icon0
watch icon2

23
24
25
26
27
28
29
30
31
    .forBrowser('firefox')
    .build();

  // Returns a promise that resolves to the element
  this.waitForElement = function(locator) {
    var condition = seleniumWebdriver.until.elementLocated(locator);
    return this.driver.wait(condition)
  }
}
fork icon0
star icon0
watch icon2