WebDriverJs

jleyba edited this page Mar 11, 2016 · 6 revisions

Quick Start Guide

npm install selenium-webdriver
// google_search.js
var webdriver = require('selenium-webdriver'),
    By = webdriver.By,
    until = webdriver.until;

var driver = new webdriver.Builder()
    .forBrowser('firefox')
    .build();

driver.get('http://www.google.com/ncr');
driver.findElement(By.name('q')).sendKeys('webdriver');
driver.findElement(By.name('btnG')).click();
driver.wait(until.titleIs('webdriver - Google Search'), 1000);
driver.quit();
node google_search

API Documentation

The JavaScript API documentation is published with each release and available here. Please file bug reports for any missing or unclear information in the API docs.

Understanding the Promise Manager

WebDriver's JavaScript API is entirely asynchronous and every command results in a promise. Promise-heavy APIs will be a lot easier to work with once Node supports ES2017's async functions, but in the meantime, WebDriverJS uses a custom promise library with a promise manager called the ControlFlow. The ControlFlow implicitly synchronizes asynchronous actions, making it so you only have to register a promise callback when you want to catch an error or access a return value. Detailed information on the ControlFlow and WebDriverJS's promise library is included with the API docs.