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.
Asked
Active
Viewed 3,386 times
2 Answers
6
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
});

Xolv.io
- 2,483
- 1
- 15
- 17
1
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

ragulka
- 4,312
- 7
- 48
- 73