Attempting to utilize Java Selenium WebDriver to capture all JavaScript errors on a webpage.
Below is a snippet of the code I am using:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.logging.LogEntries;
import org.openqa.selenium.logging.LogType;
public class MainExample {
public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "path_to_driver/geckodriver");
FirefoxOptions options = new FirefoxOptions();
WebDriver driver = new FirefoxDriver(options);
driver.get("https://www.google.com");
LogEntries entries = driver.manage().logs().get(LogType.BROWSER);
}
}
Utilizing geckodriver version 0.30.0-linux64.tar.gz for the Firefox driver.
Here's my Selenium version:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.1.1</version>
</dependency>
Encountering an exception when running the code above:
Driver info: driver.version: RemoteWebDriver at org.openqa.selenium.json.JsonInput.peek(JsonInput.java:122) at org.openqa.selenium.json.JsonTypeCoercer.lambda$null$6(JsonTypeCoercer.java:140) at org.openqa.selenium.json.JsonTypeCoercer.coerce(JsonTypeCoercer.java:126) at org.openqa.selenium.json.Json.toType(Json.java:69) at org.openqa.selenium.json.Json.toType(Json.java:55) at org.openqa.selenium.json.Json.toType(Json.java:50) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:87) at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158) at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552) at org.openqa.selenium.remote.RemoteExecuteMethod.execute(RemoteExecuteMethod.java:35) at org.openqa.selenium.remote.RemoteLogs.getRemoteEntries(RemoteLogs.java:81) at org.openqa.selenium.remote.RemoteLogs.get(RemoteLogs.java:77) at MainExample.main(MainExample.java:17)
JavaScript errors are visible in the logs while running the code on a custom page with Java script errors, but cannot retrieve them using:
driver.manage().logs().get(LogType.BROWSER);
Attempted various solutions from this related subject, but consistently encountering the same error.
Tried downgrading Selenium version to 3.141.59, however still facing the issue.