View Source Improve this doc

selectorExecuteAsync

Works just like execute, only you can use Selenium selector strategies to pass html elements to the asynchronous function you wish to execute in the browser.

The asynchronous function fn will receive every resolved selector as an array of html elements, even if there is only one result, or no result. These arrays are the first arguments the function fn receives. If you pass an array of selectors, the resulting html element arrays are returned in the same order.

All arguments you append after function fn are added as the arguments after the html arrays. You can use any JSON value or a function as such an argument.

Usage

1
2
browser.selectorExecuteAsync(selectors,script[,argument1,...,argumentN]);

Parameters

Param Type Details
selectors String/Array. single selector or array of selectors
script Function asynchronous function to get executed in the browser
argument1,…,argumentN …* arguments added to fn. Can be any JSON value or function

Example

selectorExecuteAsync.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
it('should be able to inject JavaScript into the page that can be execute asynchronously', function () {
var divCount = browser.selectorExecuteAsync("//div", function(divs, message, callback) {
callback(divs.length + message);
}, " divs on the page")
console.log(divCount); // returns, for example, "68 divs on the page"
var divLinkCount = browser.selectorExecuteAsync(["//div", "=Read Post"], function(divs, links, callback) {
var message = 'There are ';
message += divs.length + ' divs on the page';
message += ' and ';
message += links.length + ' links with an link text "' + links[0].text + '"';
callback(message);
})
console.log(divLinkCount); // returns, for example, "There are 68 divs on the page and 42 links with an link text 'Read Post'"
});

Uses