Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.Error: Unresolved compilation problems : WebDriver/ChromeDriver cannot be resolved to a type error while executing selenium tests

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

like image 493
Samraj Avatar asked Dec 19 '25 22:12

Samraj


1 Answers

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.
like image 97
undetected Selenium Avatar answered Dec 21 '25 16:12

undetected Selenium



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!