View Source Improve this doc

selectorExecute

Works just like execute, only you can use selectors to pass html elements to the function you wish to execute in the browser.

The 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.selectorExecute(selectors,script[,argument1,...,argumentN]);

Parameters

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

Example

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

Uses