3

I'm using Selenium 2.20 with Firefox 10.

When i execute JavaScript code:

try {    
  ((JavascriptExecutor) webDriver.executeScript(script, args);
} catch(Exception e) {
  System.err.println(e.getMessage());
}

and the code contains or produces a JavaScript exception, i am not able to retrieve the error message. Instead it returns null most of the time.

I also tried this JS code:

// error handling
window.onerror = function(msg, url, linenumber) {
    var error = document.createAttribute("javaScriptErrorMessage");
    error.nodeValue = msg + "\n  at line number " + linenumber + " (URL: " + url + ")";
    document.getElementsByTagName("body")[0].setAttributeNode(error);
};

But that doesn't seem to work either. When i try to get the error attribute in the body tag, it also equals null.

This is the Exception i get in Java:

org.openqa.selenium.WebDriverException: null (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 8 milliseconds
Build info: version: '2.20.0', revision: '16008', time: '2012-02-28 15:00:40'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.35-32-generic', java.version: '1.6.0_20'
Driver info: driver.version: RemoteWebDriver

The relevant part seems to be the message WARNING: The server did not provide any stacktrace information. But i have no clue why this happens. Maybe a Firefox setting which needs to be changed?

Do i use the JavascriptExecutor wrongly?

4
  • You use JavascriptExecutor right. This is what I can say. Did you try with any other Driver? Commented Mar 5, 2012 at 20:36
  • No, i did not try another Driver because i think Firefox is the best bet when it comes to stability, performance and future updates. But i may be wrong. Commented Mar 5, 2012 at 21:11
  • 2
    I disagree. From my experience ChromeDriver has been the most stable of the lot. Firefox has had its issues with native events on and off. Commented May 22, 2012 at 10:53
  • The only problem with ChromeDriver is the additional library which is platform-dependent and needs to be downloaded seperately. Commented May 22, 2012 at 11:11

1 Answer 1

3

You always need to return something when using a JavascriptExecutor, try doing:

try {    
  ((JavascriptExecutor) webDriver.executeScript("return " + script, args);
} catch(Exception e) {
  System.err.println(e.getMessage());
}
Sign up to request clarification or add additional context in comments.

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.