How to execute custom javascript code in webdriverjs

how to execute custom javascript code in webdriverjs ( https://code.google.com/p/selenium/wiki/WebDriverJs ) I found the execute method, but its purpose is completely different.

+2
source share
2 answers

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
});
+6
source

If you use camme / webdriverjs in 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 get the number of list items using jquery. We process the result in a callback function, referring to result.value.

It is also available here: https://gist.github.com/ragulka/10458018

+1

All Articles