Reputation: 276
how to execute custom javascript code in webdriverjs ( https://code.google.com/p/selenium/wiki/WebDriverJs ) I found execute method but it`s purpose is completly different.
Upvotes: 3
Views: 3401
Reputation: 4342
If you're using camme/webdriverjs on node, you can use the following snippet:
client
.execute(function() {
return $('ul li').length;
}, [], function (err, result) {
console.log(result.value); // 4
})
.call(done);
Here, we are getting the number of list-items using jquery. We handle the result in the callback function, by accessing result.value
.
It's also available as a gist here: https://gist.github.com/ragulka/10458018
Upvotes: 1
Reputation: 2533
Here you go:
var yourClientJSFunction = function (param1, param2) {
// the JS code you want to run in the browser
}
driver.executeAsyncScript(yourClientJSFunction, param1, param2).then(function (res) {
// deal with the response
});
Upvotes: 6