Selenium WebDriver usage triggers Cannot initialize cryptographic mechanism at java.base/javax.crypto.JceSecurity on windows 10 machine for both Eclipse and IntelliJ Idea projects. Please guide/suggest on how to fix the error. I had setup this as maven project with JDK 17.0.2 and trying to execute a basic selenium test. I have checked thoroughly, there are no other versions of java installed on my machine.
package testcase;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;
public class MyFristTest {
public static void main(String[] args) throws InterruptedException {
System.out.println("Testing the program!");
// **WebDriverManager.chromedriver().setup();**
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "E:\\Softwares\\Selenium\\selenium-chrome-driver-4.1.2.jar");
**driver = new ChromeDriver();**
driver.get("https://www.zoho.com/");
Thread.sleep(5000);
driver.findElement(By.linkText("Sign in")).click();
Thread.sleep(5000);
driver.findElement(By.id("login_id")).sendKeys("[email protected]");
driver.findElement(By.xpath("//form[@id='login']//button[@id='nextbtn']")).click();
driver.findElement(By.xpath("//input[@id='password']")).sendKeys("testing!23");
driver.findElement(By.xpath("//form[@id='login']//button[@id='nextbtn']")).click();
driver.quit();
}
}
Receiving same errors in both eclipse and IntelliJ.
WebDriverManager.chromedriver().setup();
and if I comment above line, I receive error for the below line
driver = new ChromeDriver();
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.base/javax.crypto.Cipher.getInstance(Cipher.java:546)
at java.base/sun.security.ssl.SSLCipher.isTransformationAvailable(SSLCipher.java:511)
at java.base/sun.security.ssl.SSLCipher.<init>(SSLCipher.java:500)
at java.base/sun.security.ssl.SSLCipher.<clinit>(SSLCipher.java:82)
at java.base/sun.security.ssl.CipherSuite.<clinit>(CipherSuite.java:65)
at java.base/sun.security.ssl.SSLContextImpl.getApplicableSupportedCipherSuites(SSLContextImpl.java:343)
at java.base/sun.security.ssl.SSLContextImpl$AbstractTLSContext.<clinit>(SSLContextImpl.java:556)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:375)
at java.base/java.security.Provider$Service.getImplClass(Provider.java:1933)
at java.base/java.security.Provider$Service.getDefaultConstructor(Provider.java:1964)
at java.base/java.security.Provider$Service.newInstanceOf(Provider.java:1878)
at java.base/java.security.Provider$Service.newInstanceUtil(Provider.java:1886)
at java.base/java.security.Provider$Service.newInstance(Provider.java:1861)
at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:236)
at java.base/sun.security.jca.GetInstance.getInstance(GetInstance.java:164)
at java.base/javax.net.ssl.SSLContext.getInstance(SSLContext.java:185)
at io.netty.handler.ssl.JdkSslContext.<clinit>(JdkSslContext.java:74)
at io.netty.handler.ssl.SslContext.newClientContextInternal(SslContext.java:824)
at io.netty.handler.ssl.SslContextBuilder.build(SslContextBuilder.java:611)
at org.asynchttpclient.netty.ssl.DefaultSslEngineFactory.buildSslContext(DefaultSslEngineFactory.java:59)
at org.asynchttpclient.netty.ssl.DefaultSslEngineFactory.init(DefaultSslEngineFactory.java:74)
at org.asynchttpclient.netty.channel.ChannelManager.<init>(ChannelManager.java:104)
at org.asynchttpclient.DefaultAsyncHttpClient.<init>(DefaultAsyncHttpClient.java:92)
at org.asynchttpclient.Dsl.asyncHttpClient(Dsl.java:32)
at org.openqa.selenium.remote.http.netty.NettyClient.createHttpClient(NettyClient.java:105)
at org.openqa.selenium.remote.http.netty.NettyClient.<clinit>(NettyClient.java:50)
at org.openqa.selenium.remote.http.netty.NettyClient$Factory.createClient(NettyClient.java:146)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:107)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:94)
at org.openqa.selenium.remote.HttpCommandExecutor.<init>(HttpCommandExecutor.java:85)
at org.openqa.selenium.remote.service.DriverCommandExecutor.<init>(DriverCommandExecutor.java:80)
at org.openqa.selenium.chromium.ChromiumDriverCommandExecutor.<init>(ChromiumDriverCommandExecutor.java:35)
at org.openqa.selenium.chrome.ChromeDriver$ChromeDriverCommandExecutor.<init>(ChromeDriver.java:118)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:106)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:93)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:48)
at testcase.MyFristTest.main(MyFristTest.java:16)
Caused by: java.lang.SecurityException: Can not initialize cryptographic mechanism
at java.base/javax.crypto.JceSecurity.<clinit>(JceSecurity.java:119)
... 38 more
Caused by: java.lang.SecurityException: Can't read cryptographic policy directory: unlimited
at java.base/javax.crypto.JceSecurity.setupJurisdictionPolicies(JceSecurity.java:333)
at java.base/javax.crypto.JceSecurity$1.run(JceSecurity.java:110)
at java.base/javax.crypto.JceSecurity$1.run(JceSecurity.java:107)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
at java.base/javax.crypto.JceSecurity.<clinit>(JceSecurity.java:106)
... 38 more
Below is the POM used for Maven setup.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ski</groupId>
<artifactId>HybridFramework</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<selenium-java-version>4.1.2</selenium-java-version>
<slf4j.version>1.7.36</slf4j.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${selenium-java-version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-api -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>${selenium-java-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.5</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.uncommons/reportng -->
<dependency>
<groupId>org.uncommons</groupId>
<artifactId>reportng</artifactId>
<version>1.1.4</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.1.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies>
</project>
ExceptionInInitializerError
ExceptionInInitializerError implies that an unexpected exception has occurred in a static initializer which indicates that an exception occurred during evaluation of a static initializer or the initializer for a static variable.
This usecase
Within the System.setProperty() line the key
webdriver.chrome.driver
should be used to pass the absolute path of the ChromeDriver binary/executable. So instead of passingselenium-chrome-driver-4.1.2.jar
you need to passchromedriver.exe
.Solution
Effectively, your line of code will be: