How to Report Javascript Errors with Selenium WebDriver

Almost all websites use some level of Javascript to do some operations on the UI. During manual testing, when using the chrome browser, we can check for Javascript errors by inspecting the console of the developer tools.

To report Javascript errors with Selenium WebDriver, we need to add a JSERROR Collector jar to our project by adding the below dependency to the POM file:


We also need to add a firefox addon to firefox profile in the setup of the automated tests to be able to catch Javascript errors in Selenium WebDriver. Click to Download the firefox addon.

Below is a sample WebDriver code which makes use of the above library and the firefox addon to report Javascript errors:

public class JSErrorTest {

    public static WebDriver wbdv = null;
    public static EventFiringWebDriver driver=null;

    public static void setUp() throws IOException {
        System.setProperty("webdriver.firefox.bin","C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
        try {
            ProfilesIni allProfiles = new ProfilesIni();
            FirefoxProfile profile = allProfiles.getProfile("default");
            wbdv = new FirefoxDriver(profile);
            driver = new EventFiringWebDriver(wbdv);
        } catch(Throwable t) {


    public static void tearDown() {
        List<JavaScriptError> jsErrors = JavaScriptError.readErrors(driver);
        System.out.println("###start displaying errors");
        for(int i = 0; i < jsErrors.size(); i++)
        System.out.println("###start displaying errors");
        driver.close(); driver.quit();

    public void returnJavascriptErrors() throws InterruptedException {
    //do your steps


Leave a Reply