Readonly
[toCreates a new action sequence using this driver. The sequence will not be scheduled for execution until actions.ActionSequence#perform is called. Example:
driver.actions().
mouseDown(element1).
mouseMove(element2).
mouseUp().
perform();
Optional
options: { A new action sequence for this instance.
Attaches a callback for only the rejection of the Promise.
Optional
onrejected: null | ((reason) => TResult | PromiseLike<TResult>)The callback to execute when the Promise is rejected.
A Promise for the completion of the callback.
Schedules a command.Command to be executed by this driver's command.Executor.
The command to schedule.
Optional
description: stringA description of the command for debugging.
A promise that will be resolved with the command result.
Schedules a command to execute asynchronous JavaScript in the context of the currently selected frame or window. The script fragment will be executed as the body of an anonymous function. If the script is provided as a function object, that function will be converted to a string for injection into the target window.
Any arguments provided in addition to the script will be included as script arguments and may be referenced using the {@code arguments} object. Arguments may be a boolean, number, string, or {@code WebElement}. Arrays and objects may also be used as script arguments as long as each item adheres to the types previously mentioned.
Unlike executing synchronous JavaScript with #executeScript, scripts executed with this function must explicitly signal they are finished by invoking the provided callback. This callback will always be injected into the executed function as the last argument, and thus may be referenced with {@code arguments[arguments.length - 1]}. The following steps will be taken for resolving this functions return value against the first argument to the script's callback function:
Example #1: Performing a sleep that is synchronized with the currently selected window:
var start = new Date().getTime();
driver.executeAsyncScript(
'window.setTimeout(arguments[arguments.length - 1], 500);').
then(function() {
console.log(
'Elapsed time: ' + (new Date().getTime() - start) + ' ms');
});
Example #2: Synchronizing a test with an AJAX application:
var button = driver.findElement(By.id('compose-button'));
button.click();
driver.executeAsyncScript(
'var callback = arguments[arguments.length - 1];' +
'mailClient.getComposeWindowWidget().onload(callback);');
driver.switchTo().frame('composeWidget');
driver.findElement(By.id('to')).sendKeys('dog@example.com');
Example #3: Injecting a XMLHttpRequest and waiting for the result. In this example, the inject script is specified with a function literal. When using this format, the function is converted to a string for injection, so it should not reference any symbols not defined in the scope of the page under test.
driver.executeAsyncScript(function() {
var callback = arguments[arguments.length - 1];
var xhr = new XMLHttpRequest();
xhr.open('GET', '/resource/data.json', true);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
callback(xhr.responseText);
}
}
xhr.send('');
}).then(function(str) {
console.log(JSON.parse(str)['food']);
});
The script to execute.
Rest
...var_args: any[]The arguments to pass to the script.
A promise that will resolve to the scripts return value.
Schedules a command to execute JavaScript in the context of the currently selected frame or window. The script fragment will be executed as the body of an anonymous function. If the script is provided as a function object, that function will be converted to a string for injection into the target window.
Any arguments provided in addition to the script will be included as script arguments and may be referenced using the {@code arguments} object. Arguments may be a boolean, number, string, or {@code WebElement}. Arrays and objects may also be used as script arguments as long as each item adheres to the types previously mentioned.
The script may refer to any variables accessible from the current window. Furthermore, the script will execute in the window's context, thus {@code document} may be used to refer to the current document. Any local variables will not be available once the script has finished executing, though global variables will persist.
If the script has a return value (i.e. if the script contains a return statement), then the following steps will be taken for resolving this functions return value:
The script to execute.
Rest
...var_args: any[]The arguments to pass to the script.
A promise that will resolve to the scripts return value.
Attaches a callback that is invoked when the Promise is settled (fulfilled or rejected). The resolved value cannot be modified from the callback.
Optional
onfinally: null | (() => void)The callback to execute when the Promise is settled (fulfilled or rejected).
A Promise for the completion of the callback.
Schedule a command to find an element on the page. If the element cannot be found, a bot.ErrorCode.NO_SUCH_ELEMENT result will be returned by the driver. Unlike other commands, this error cannot be suppressed. In other words, scheduling a command to find an element doubles as an assert that the element is present on the page. To test whether an element is present on the page, use #findElements.
The search criteria for an element may be defined using one of the factories in the By namespace, or as a short-hand By.Hash object. For example, the following two statements are equivalent:
var e1 = driver.findElement(By.id('foo'));
var e2 = driver.findElement({id:'foo'});
You may also provide a custom locator function, which takes as input this instance and returns a WebElement, or a promise that will resolve to a WebElement. If the returned promise resolves to an array of WebElements, WebDriver will use the first element. For example, to find the first visible link on a page, you could write:
var link = driver.findElement(firstVisibleLink);
function firstVisibleLink(driver) {
var links = driver.findElements(By.tagName('a'));
return promise.filter(links, function(link) {
return link.isDisplayed();
});
}
The locator to use.
A WebElement that can be used to issue commands against the located element. If the element is not found, the element will be invalidated and all scheduled commands aborted.
The locator function to use.
The search context.
A promise that will resolve to a list of WebElements.
Schedule a command to search for multiple elements on the page.
The locator to use.
A promise that will resolve to an array of WebElements.
The locator function to use.
The search context.
A promise that will resolve to an array of WebElements.
A promise that will resolve with the this instance's capabilities.
Schedules a command to retrieve the current page's source. The page source returned is a representation of the underlying DOM: do not expect it to be formatted or escaped in the same way as the response sent from the web server.
A promise that will be resolved with the current page source.
Retrieves 'webSocketDebuggerUrl' by sending a http request using debugger address
Returns parsed webSocketDebuggerUrl obtained from the http request
The navigation interface for this instance.
The webElement in unresolved state
First single WebElement from array of resolved promises
Handle Network interception requests
WebSocket connection to the browser
Object representing what we are intercepting as well as what should be returned.
callback called when we intercept requests.
Sets the input.FileDetector file detector that should be used with this instance.
The detector to use or {@code null}.
The target locator interface for this instance.
Schedule a command to take a screenshot. The driver makes a best effort to return a screenshot of the following, in order of preference:
A promise that will be resolved to the screenshot as a base-64 encoded PNG.
Attaches callbacks for the resolution and/or rejection of the Promise.
Optional
onfulfilled: null | ((value) => TResult1 | PromiseLike<TResult1>)The callback to execute when the Promise is resolved.
Optional
onrejected: null | ((reason) => TResult2 | PromiseLike<TResult2>)The callback to execute when the Promise is rejected.
A Promise for the completion of which ever callback is executed.
Schedules a command to wait for a condition to hold. The condition may be specified by a Condition, as a custom function, or as a Promise.
For a Condition or function, the wait will repeatedly evaluate the condition until it returns a truthy value. If any errors occur while evaluating the condition, they will be allowed to propagate. In the event a condition returns a Promise promise, the polling loop will wait for it to be resolved and use the resolved value for whether the condition has been satisified. Note the resolution time for a promise is factored into whether a wait has timed out.
Note, if the provided condition is a WebElementCondition, then the wait will return a WebElementPromise that will resolve to the element that satisified the condition.
Example: waiting up to 10 seconds for an element to be present and visible on the page.
var button = driver.wait(until.elementLocated(By.id('foo'), 10000);
button.click();
This function may also be used to block the command flow on the resolution of a Promise promise. When given a promise, the command will simply wait for its resolution before completing. A timeout may be provided to fail the command if the promise does not resolve before the timeout expires.
Example: Suppose you have a function, startTestServer
, that returns a
promise for when a server is ready for requests. You can block a
WebDriver
client on this promise with:
var started = startTestServer();
driver.wait(started, 5 * 1000, 'Server should start within 5 seconds');
driver.get(getServerUrl());
The condition to wait on, defined as a promise, condition object, or a function to evaluate as a condition.
Optional
opt_timeout: numberHow long to wait for the condition to be true.
Optional
opt_message: stringAn optional message to use if the wait times out.
Optional
opt_pollTimeout: numberDuration in milliseconds to wait between polling the condition.
A promise that will be fulfilled with the first truthy value returned by the condition function, or rejected if the condition times out.
Schedules a command to wait for a condition to hold. The condition may be specified by a webdriver.Condition, as a custom function, or as a Promise.
For a webdriver.Condition or function, the wait will repeatedly evaluate the condition until it returns a truthy value. If any errors occur while evaluating the condition, they will be allowed to propagate. In the event a condition returns a Promise promise, the polling loop will wait for it to be resolved and use the resolved value for whether the condition has been satisified. Note the resolution time for a promise is factored into whether a wait has timed out.
Note, if the provided condition is a WebElementCondition, then the wait will return a WebElementPromise that will resolve to the element that satisified the condition.
Example: waiting up to 10 seconds for an element to be present and visible on the page.
var button = driver.wait(until.elementLocated(By.id('foo'), 10000);
button.click();
This function may also be used to block the command flow on the resolution of a Promise promise. When given a promise, the command will simply wait for its resolution before completing. A timeout may be provided to fail the command if the promise does not resolve before the timeout expires.
Example: Suppose you have a function, startTestServer
, that returns a
promise for when a server is ready for requests. You can block a
WebDriver
client on this promise with:
var started = startTestServer();
driver.wait(started, 5 * 1000, 'Server should start within 5 seconds');
driver.get(getServerUrl());
The condition to wait on, defined as a promise, condition object, or a function to evaluate as a condition.
Optional
opt_timeout: numberHow long to wait for the condition to be true.
Optional
opt_message: stringAn optional message to use if the wait times out.
Optional
opt_pollTimeout: numberDuration in milliseconds to wait between polling the condition.
A promise that will be fulfilled with the first truthy value returned by the condition function, or rejected if the condition times out.
Generated using TypeDoc
A thenable wrapper around a webdriver.IWebDriver IWebDriver instance that allows commands to be issued directly instead of having to repeatedly call
then
:If the driver instance fails to resolve (e.g. the session cannot be created), every issued command will fail.