Capture All The JavaScript Errors Using Selenium Webdriver

This post helps you to Capture all the JavaScript Errors

import java.util.List;
import net.jsourcerer.webdriver.jserrorcollector.JavaScriptError;
import org.openqa.selenium.firefox.FirefoxProfile;

public void setUp() throws Exception {
FirefoxProfile ffProfile = new FirefoxProfile();
driver = new FirefoxDriver(ffProfile);
baseUrl = “”;

public void contentTitle() throws Exception {
driver.get(baseUrl + “/”);

public void tearDown() throws Exception {
List jsErrors = JavaScriptError.readErrors(driver);
System.out.println(“——————START displaying JS errors——————”);
for (int i = 0; i < jsErrors.size(); i++) {
System.out.println("Error in Line: "+ jsErrors.get(i).getLineNumber());
System.out.println("——————STOP displaying JS errors———————");

4 thoughts on “Capture All The JavaScript Errors Using Selenium Webdriver

  1. armatearjun June 15, 2015 / 2:13 pm

    is this comes with selenium server or is this an external package? import net.jsourcerer.webdriver.jserrorcollector.JavaScriptError;, if i try to add the same it says cannot be resolved…


    • charan163 June 15, 2015 / 2:50 pm

      Its Java Utils package


  2. autumnator December 8, 2016 / 2:24 am

    Unfortunately this is geared towards FF and not browser agnostic.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s