简体   繁体   中英

chrome Webdriver can't be resolved to a type error eclipse and java

Im trying to do some automation projects with chrome, java and selenium and having problems importing the chrome driver.

package main;

import org.openqa.selenium.*;

public class SitePoster {

    public static void main(String[] args) {
         //System.setProperty("webdriver.chrome.driver", "./pathtodriver");
        WebDriver driver = new ChromeDriver();
        //Getting error saying "ChromeDriver can't be resolved to a type"
    } 

}

chrome Webdriver can't be resolved to a type error eclipse and java:-

I was getting same problem with selenium -java 3.141.59 on macOs.Check below steps to resolve issue:-

  1. Create a new Java Project >class >Create Class name
  2. Right click on Project >Property > Build path > Libraries
  3. Add external Jars to Classpath download from selenium client & web driver language binding.
  4. Apply and Close.

Hope you got your Issue fixed. Kindly reply back in case of any issue.

Even after installing the required jar files I was facing the same error message and then I updated the compiler compliance level in the Java compiler to 1.8(depends) and then error disappeared. It solved my issue.

You can follow below steps:

  1. Select the Java project(created one)

  2. Build Path

  3. Configure build path

  4. Java compiler

  5. Change the compiler compliance level(I selected 1.8)

  6. Apply and Close.

The solution for me was the POM specified an older version of ChromeDriverManager which was how chromeDriver was obtained in my build. If you are specifying a location using setProperty this will of course not apply to you. But it helps to check with the version of the dependencies in your POM

<dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>3.6.1</version>
        <scope>test</scope>
    </dependency>

That did it!

Add Selenium Jar Files to ClassPath instead of ModulePath在此处输入图片说明

ChromeDriver is one extra level nested in org.openqa.selenium package. Try with import statement

org.openqa.selenium.chrome.*;

OR

import org.openqa.selenium.chrome.ChromeDriver;

The error says it all :

"ChromeDriver can't be resolved to a type"

While working with Selenium 3.x you have to mention the Key-Value pair through System.setProperty() line mandatory as follows :

System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");

Additionally, as per best practices instead of import org.openqa.selenium.*; you have to mention the individual packages for import as follows :

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver; 

I was getting the exact same error. It did resolve for me after performing the below steps.

  1. Right click on Project>Buildpath>configure build path
  2. Libraries>Add external Jars.
  3. Add the external Jars from the 'libs' folder first, then add the 'Client component' ones.

     import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class test1 { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\\\\Users\\\\nsukumar\\\\Documents\\\\selenium\\\\chromedriver_win32\\\\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("https://google.co.in"); } }

Try to edit external jars in the ModulePath & Classpath .

See on the picture link -->在此处输入图片说明

You need to attach jar files. I was getting the exactly the same issue. you need to install "Selenium 3.4.0" jar files. Which contains lib folder of .jar files and "client-combined-3.4.0-nodeps" files. After you attach these jar files refresh the code by giving run command.

从构建路径添加 Selenium jar 文件 > 添加外部库为我解决了这个问题。

For Linux user go to terminal check google version with below command

google-chrome --version

OP :- Google Chrome 69.0.3497.100

Now, Upgrade chrome using below command

sudo apt --only-upgrade install google-chrome-stable

After this check the google chrome version using above same command

google-chrome --version

OP :- Google Chrome 78.0.3904.87

Now you need to download the same version google driver. you can find it from the below link.

https://chromedriver.storage.googleapis.com/index.html?path=78.0.3904.70/

Download google driver and extract it and save the path and use it in the code, Now run the code.

if you are not able to add this statement

 import org.openqa.selenium.chrome.ChromeDriver;

the probable reason is you are using maven and you have not included the below

<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.141.59</version>
</dependency>

Even if we put the below statement, problem still comes

    System.setProperty("webdriver.chrome.driver", "C:\\Software\\chromedriver_win32\\chromedriver.exe");

So the solution is goto maven repository site and take the chrome dependency from there to solve this problem

This type of error occurs when you have added the external jars in the ModulePath. To resolve this issue, you can remove the external jars from the node "Modulepath". Select the node "Classpath" then add the external jars. Review that all the jars are under the node "Classpath"

When adding external jars, make sure you add the jars in the lib folder first before adding the ones in the main selenium-java folder. This made the difference for me.

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class testdemo {

    public static void main(String[] args) {
        
        // TODO Auto-generated method stub
        System.setProperty("webdriver.chrome.driver","C:\\Users\\victo\\OneDrive\\Documents\\driverchrome\\ChromeDriver.exe");
        
        WebDriver driver=new ChromeDriver();
        
        driver.get(" https:google.com");

I faced this error when using Latest Eclipse 2021-03 and Selenium 3

To resolve this, add your Selenium standalone jar file in Classpath instead of Module path. also do not forgot to delete the existing Jar files in modulepath, apply and then apply&close.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM