Class: WebDriver

WebDriver

new WebDriver()

Driver constructor
Parameters:
Name Type Argument Description
params.host String <optional>
Target selenium host
params.port Number <optional>
Target selenium port
params.desiredCapabilities Object <optional>
Desired capabilities which will passed to the selenium server
params.timeouts Object <optional>
Timeouts object which will be set using `setTimeouts` method
params.defaults Object <optional>
Default values for different methods parameters (e.g. params.defaults.using will be used by `get`, `getList`, `waitForElement`, etc)
Source:

Members

element :Object

element object combines WebDriver#get with WebElement methods. So you can call any WebElement method with selector and params (optionally). Same parameters as for normal WebElement method call will be passed to the callback. Internally WebDriver#get then target method of WebElement will be called therefore if you need to call several methods on same element it make sense(due performance) to get element and then call it's methods.
Type:
  • Object
Source:
Examples
// driver is an instance of WebDriver
driver.element.sendKeys(
  '[name="user[login]"]',
  'patrik',
  function(err, element) {
    // element is WebElement which was get
  }
);
// driver is an instance of WebDriver
driver.element.getValue('[name="user[login]"]', function(err, login) {
  // login equals to 'patrik'
});

Methods

back(callback(err:Error,driver:WebDriver))

Navigate backwards in the browser history, if possible.
Parameters:
Name Type Description
callback(err:Error,driver:WebDriver) function
Source:

click(button, callback(err:Error,driver:WebDriver))

Click any mouse button (at the coordinates set by the last moveto command). Note that calling this command after calling buttondown and before calling button up (or any out-of-order interactions sequence) will yield undefined behaviour).
Parameters:
Name Type Argument Description
button String <optional>
Could be left, middle or right(left used by default)
callback(err:Error,driver:WebDriver) function
Source:

deleteCookie(name, callback(err:Error,driver:WebDriver))

Delete all cookies or cookie with given name.
Parameters:
Name Type Argument Description
name String <optional>
callback(err:Error,driver:WebDriver) function
Source:

deleteSession(callback(err:Error))

End current driver session
Parameters:
Name Type Description
callback(err:Error) function
Source:

execute(script, args, isAsync, callback(err:Error))

Inject a snippet of JavaScript into the page for execution in the context of the currently selected frame.
Parameters:
Name Type Description
script String
args Any[] Script arguments
isAsync Boolean
callback(err:Error) function
Source:

forward(callback(err:Error,driver:WebDriver))

Navigate forwards in the browser history, if possible.
Parameters:
Name Type Description
callback(err:Error,driver:WebDriver) function
Source:

get(selector, params, callback(err:Error,element:WebElement))

Get element from current page. Error will be returned if no such element on the page.
Parameters:
Name Type Argument Description
selector String Element selector
params Object <optional>
Properties
Name Type Argument Description
noError Boolean <optional>
If true then null will be passed to callback instead of timeout error.
using String <optional>
Strategy for selector (e.g. 'css selector', 'jquery'), this.defaults.using will be used by default.
chain Object[] <optional>
Traversing functions chain for jquery strategy e.g. '[{closest: 'span'}, {next: 'div'}]'
cssFilter Object <optional>
Object with css properties and values for filter result elements (using jquery.css method) e.g. '{opacity: '1'}'
callback(err:Error,element:WebElement) function
Source:

getCapabilities(callback(err:Error,capabilities:Object))

Retrieve the capabilities of the current session
Parameters:
Name Type Description
callback(err:Error,capabilities:Object) function
Source:

getList(selector, params, callback(err:Error,element:WebElement[]))

Get elements from current page. Empty array will be returned if no such elements on the page. `selector` and `params` could accept same values as at WebDriver#get.
Parameters:
Name Type Argument Description
selector String
params Object <optional>
callback(err:Error,element:WebElement[]) function
Source:

getTimeout(type, callback(err:Error,timeout:Number))

Get timeout by type
Parameters:
Name Type Description
type String
callback(err:Error,timeout:Number) function
Source:

getTitle(callback(err:Error,title:String))

Get title of current page
Parameters:
Name Type Description
callback(err:Error,title:String) function
Source:

getUrl(callback(err:Error,url:String))

Get url of current page
Parameters:
Name Type Description
callback(err:Error,url:String) function
Source:

init(callback(err:Error,driver:WebDriver))

Start driver session and return driver
Parameters:
Name Type Description
callback(err:Error,driver:WebDriver) function
Source:

makeScreenshot(path, callback(err:Error))

Make screenshot and save it to target path.
Parameters:
Name Type Description
path String
callback(err:Error) function
Source:

maximizeWindow(callback(err:Error,driver:WebDriver))

Maximize current window.
Parameters:
Name Type Description
callback(err:Error,driver:WebDriver) function
Source:

mouseDown(button, callback(err:Error,driver:WebDriver))

Click and hold mouse button (at the coordinates set by the last moveto command). Note that the next mouse-related command that should follow is buttonup . Any other mouse command (such as click or another call to buttondown) will yield undefined behaviour.
Parameters:
Name Type Argument Description
button String <optional>
Could be left, middle or right(left used by default)
callback(err:Error,driver:WebDriver) function
Source:

mouseUp(button, callback(err:Error,driver:WebDriver))

Releases the mouse button previously held (where the mouse is currently at). Must be called once for every buttondown command issued. See the note in click and buttondown about implications of out-of-order commands.
Parameters:
Name Type Argument Description
button String <optional>
Could be left, middle or right(left used by default)
callback(err:Error,driver:WebDriver) function
Source:

refresh(callback(err:Error,driver:WebDriver))

Refresh the current page.
Parameters:
Name Type Description
callback(err:Error,driver:WebDriver) function
Source:

sendKeys(value, callback(err:Error,driver:WebDriver))

Send a sequence of key strokes to the active element.
Parameters:
Name Type Description
value String
callback(err:Error,driver:WebDriver) function
Source:

setTimeout(type, timeout, callback(err:Error,driver:WebDriver))

Set timeout
Parameters:
Name Type Description
type String
timeout Number timeout in ms
callback(err:Error,driver:WebDriver) function
Source:

setTimeouts(timeout, callback(err:Error))

Set timeouts
Parameters:
Name Type Description
timeout Object Object key - timeout type, value - timeout value in ms
callback(err:Error) function
Source:

setUrl(url, callback(err:Error))

Navigate to url
Parameters:
Name Type Description
url String
callback(err:Error) function
Source:

waitFor()

Wait until waitcb from `func(waitcb)` will be called with `true` or until `params.timeout` (if not set `this.timeouts.waitFor` will be used) expired (in this case error with `params.errorMessage` will be passed to callback, if `params.noError` is not true). Note: co version of the driver has similar method - `yieldUntil`.
Source:

waitForDocumentReady(callback(err:Error,driver:WebDriver))

Wait for document ready (jquery).
Parameters:
Name Type Description
callback(err:Error,driver:WebDriver) function
Source:

waitForElement(selector, params, callback(err:Error,element:WebDriver))

Wait for element appear on current page and return it. `selector` and `params` could accept same values as at `get`.
Parameters:
Name Type Argument Description
selector String
params Object <optional>
callback(err:Error,element:WebDriver) function
Source:

waitForElementAbsent(callback(err:Error,driver:WebDriver))

Wait until element will not be on page. `selector` and `params` could accept same values as at `get`.
Parameters:
Name Type Description
callback(err:Error,driver:WebDriver) function
Source:

waitForRedirect(newUrl, callback(err:Error,driver:WebDriver))

Wait for redirect to `newUrl`. Query string is not involved in url comparation.
Parameters:
Name Type Description
newUrl String | RegExp New url
callback(err:Error,driver:WebDriver) function
Source:

waitForUrlChange(oldUrl, newUrl, params, callback(err:Error,driver:WebDriver))

Wait for url change from `oldUrl` to `newUrl`. Query string is not involved in url comparation.
Parameters:
Name Type Argument Description
oldUrl String | RegExp Old url (will be ignored if falsy)
newUrl String | RegExp New url (will be ignored if falsy)
params Object <optional>
Properties
Name Type Argument Default Description
omitQueryString Boolean <optional>
false the parameter determines whether the current and expected new URL will be checked without querystring
callback(err:Error,driver:WebDriver) function
Source: