Here is my code:
package seleniumTutorials;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class BasicsSelenium {
public static void main(String[] args) {
boolean status;
status=true;
boolean newstatus = false;
System.out.println("My Old status was "+status);
System.out.println("My new status was "+newstatus);
System.setProperty("webdriver.chrome.driver", "F:\\Samraj\\MavenAutomation\\Jar Files\\Selenium Java\\chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get("dev.findmyfare.io");
System.out.println(driver.getTitle());
}
}
Below is the error message which am getting after declaring webdriver concept:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
WebDriver cannot be resolved to a type ChromeDriver cannot be resolved to a type
at seleniumTutorials.BasicsSelenium.main(BasicsSelenium.java:13)
Note: I can able to execute simple java program.
Screenshot of my Eclipse
This error message...
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
WebDriver cannot be resolved to a type
ChromeDriver cannot be resolved to a type
...implies that WebDriver and ChromeDriver wasn't resolved at compiletime.
As per the snapshot you have shared your main issue is the presence of multiple similar binaries within your project space as follows :
- You have included selenium-server-standalone-3.11.0 as a dependency.
- Additionally you have included the Java Client JARs from selenium-java-3.11.0 as a dependency.
As a result it is pretty much possible that you have resolved the WebDriver and ChromeDriver from one JAR resource (i.e. either selenium-server-standalone-3.11.0 or selenium-java-3.11.0 JARs) but compiletime the Classes are trying to get resolved from the other JAR. Hence you see java.lang.Error: Unresolved compilation problems
Solution
- Either keep only selenium-server-standalone-3.11.0 JAR as an external JAR.
- Or keep only selenium-java-3.11.0 JARs as an external JARs.
- Remove all the other Selenium Java Client JARs.
- Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
- Take a System Reboot.
- Execute your
@Test
.
There is no issue with your code. I created a simple Selenium project and added this code and I was able to run this code without any problem.
Please see that in your External Jars you need to have the following jar files
- client-combined-3.11.0.jar
- client-combined-3.11.0-sources.jar
- byte-buddy-1.7.9.jar
- commons-codec-1.10.jar
- commons-exec-1.3.jar
- commons-logging-1.2.jar
- gson-2.8.2.jar
- guava-23.6-jre.jar
- httpclient-4.5.3.jar
- httpcore-4.4.6.jar
- okio-1.13.0.jar
- okhttp-3.9.1.jar
Edit 1 : Also remove ChromeDriver
from the Referenced Libraries
.
I had the same error while working with IntelliJ IDEA, and the solution was to update my Gradle file "build.gradle" to include
dependencies {
// https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'}
test {
useJUnitPlatform()}