Internet-Explorer – captures JavaScript errors for IE and Chrome using Selenium WebDriver

How to use WebDriver for Chrome and IE driver to catch JavaScript errors?
You can execute custom JavaScript to hook into window.onerror.

You You can tell your JavaScript to return your data to Selenium, but since you are asking about an error, I suggest you not to do so. Depending on the error, the error may break JavaScript and may prevent it from returning.

A more robust approach might be to create a server that exposes the handler to the Web and requests it from JS.

So, the JS executed from Selenium (before the error occurs) might look like this:

< p>

window.onerror = function(message, file, line) {
var asyncHR = new XMLHttpRequest();
var URL = "https://www.yourserver. com/errorlogger?file=" + file + "&line=" + line + "&message=" + message;
asyncHR.open("GET", URL, true);
asyncHR.send() ;
};

From there, let the server take care of logging-write files, databases, etc…

How to use WebDriver for Chrome And IE driver to catch JavaScript errors?

You can execute custom JavaScript to hook into window.onerror.

You can tell your JavaScript to return your data to Selenium , But since you’re asking about an error, I suggest you don’t do this. Depending on the error, the error may break JavaScript and may prevent it from returning.

A more robust method might be to create a server that reports to the Web Expose the handler, request from JS.

So, the JS executed from Selenium (before the error occurs) may look like this:

window.onerror = function(message, file, line) {
var asyncHR = new XMLHttpRequest();
var URL = "https://www.yourserver.com/errorlogger?file=" + file + "&line =" + line + "&message=" + message;
asyncHR.open("GET", URL, true);
asyncHR.send();
};

< p>From there, let the server take care of logging-writing to files, databases, etc…

Leave a Comment

Your email address will not be published.