If you have recently upgraded to the latest ChromeDriver and are encountering the “java.io.IOException: Invalid Status code=403 text=Forbidden” error, while trying to initialize ChromeDriver, then there are a couple of ways to resolve it.
Firstly, you can add dependencies and set properties to overcome this error. Add the following dependency to your project:
<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-http-jdk-client</artifactId> <version>4.8.1</version> </dependency>
Then, set the system property:
System.setProperty("webdriver.http.factory", "jdk-http-client");
Alternatively, you can use ChromeOptions arguments to overcome this error. Simply add the following argument to ChromeOptions:
options.addArguments("--remote-allow-origins=*");
Here’s a complete code snippet:
ChromeOptions options = new ChromeOptions();
options.addArguments("--remote-allow-origins=*");
ChromeDriver driver = new ChromeDriver(options);
By using either of these approaches, you can successfully initialize ChromeDriver without encountering the “java.io.IOException: Invalid Status code=403 text=Forbidden” error.