3

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.

2 Answers 2

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
});
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.