Selenium with Java: Common errors

1

"C:\Program Files\jdk-14.0.2\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.1\lib\idea_rt.jar=61978:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.2.1\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\Andrei\IdeaProjects\webDriver1\out\production\webDriver1;C:\Soft\selenium-java-3.141.59\client-combined-3.141.59.jar;C:\Soft\selenium-java-3.141.59\libs\byte-buddy-1.8.15.jar;C:\Soft\selenium-java-3.141.59\libs\commons-exec-1.3.jar;C:\Soft\selenium-java-3.141.59\libs\guava-25.0-jre.jar;C:\Soft\selenium-java-3.141.59\libs\okhttp-3.11.0.jar;C:\Soft\selenium-java-3.141.59\libs\okio-1.14.0.jar Main Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.gecko.driver system property; for more information, see https://github.com/mozilla/geckodriver. The latest version can be downloaded from https://github.com/mozilla/geckodriver/releases at com.google.common.base.Preconditions.checkState(Preconditions.java:847) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:134) at org.openqa.selenium.firefox.GeckoDriverService.access$100(GeckoDriverService.java:44) at org.openqa.selenium.firefox.GeckoDriverService$Builder.findDefaultExecutable(GeckoDriverService.java:167) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:355) at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:190) at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:147) at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125) at Main.main(Main.java:8) Process finished with exit code 1

This means the path to the required driver has not been added to the system PATH See the Selenium basics guide for instructions: Selenium WebDriver setup

2

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: session not created: This version of ChromeDriver only supports Chrome version

This error occurs when the installed Chrome version does not match the ChromeDriver version you downloaded.

Check the ChromeDriver version on its download page chromedriver.storage.googleapis.com and compare it with Chrome's version under Help → About Google Chrome.

Starting ChromeDriver 85.0.4183.87 (cd6713ebf92fa1cacc0f1a598df280093af0c5d7-refs/branch-heads/4183@{#1689}) on port 10265 Only local connections are allowed. Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe. ChromeDriver was started successfully. Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: session not created: This version of ChromeDriver only supports Chrome version 85 Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48' System info: host: 'DESKTOP-OP43ER5', ip: '169.254.57.40', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '14.0.2' Driver info: driver.version: ChromeDriver remote stacktrace: Backtrace: Ordinal0 [0x00B3D383+3134339] Ordinal0 [0x00A2A171+2007409] Ordinal0 [0x008CAEE8+569064] Ordinal0 [0x0085139F+70559] Ordinal0 [0x0084CC63+52323] Ordinal0 [0x00870DFC+200188] Ordinal0 [0x00870C1D+199709] Ordinal0 [0x0086EB0B+191243] Ordinal0 [0x00852E77+77431] Ordinal0 [0x00853E3E+81470] Ordinal0 [0x00853DC9+81353] Ordinal0 [0x00A40CD9+2100441] GetHandleVerifier [0x00CAB75A+1396954] GetHandleVerifier [0x00CAB3D9+1396057] GetHandleVerifier [0x00CB7126+1444518] GetHandleVerifier [0x00CABCE8+1398376] Ordinal0 [0x00A37F51+2064209] Ordinal0 [0x00A422EB+2106091] Ordinal0 [0x00A42411+2106385] Ordinal0 [0x00A549C4+2181572] BaseThreadInitThunk [0x755D6359+25] RtlGetAppContainerNamedObjectPath [0x77A27C24+228] RtlGetAppContainerNamedObjectPath [0x77A27BF4+180] at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:481) at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62) at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30) at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126) at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195) at java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958) at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:127) at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:502) at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:488) at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150) at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:543) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128) at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74) at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136) 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.RemoteWebDriver.startSession(RemoteWebDriver.java:213) at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:181) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:168) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:123) at Main.main(Main.java:12)

3

java: cannot find symbol

This error usually means that the By class has not been imported.

java: cannot find symbol symbol: variable By location: class Main

Read how to do this here

4

java: incompatible types: java.time.Duration cannot be converted to long

This compile-time error can occur when code written for a newer Selenium Java client is compiled against an older release. The example uses Duration, while older WebDriverWait constructors expect a long timeout.

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10.0));

java: incompatible types: java.time.Duration cannot be converted to long

A fixed delay can be used as a temporary workaround, but it is brittle and waits even when the page is ready sooner.

Prefer a version-compatible WebDriverWait condition. This older workaround imports

import java.util.concurrent.TimeUnit;

and then sleeps for a fixed interval:

try { TimeUnit.SECONDS.sleep(15); } catch (InterruptedException e) { System.out.println(("Interrupted " + "while Sleeping")); }