简体   繁体   English

WebDriver 和 ChromeDriver 无法解析为类型

[英]WebDriver and ChromeDriver cannot be resolved to a type

I know this is a very frequently asked question but i have tried so many fixes to this problem (including: downloading java and eclipse again) and none of the fixes worked.我知道这是一个非常常见的问题,但我已经尝试了很多解决这个问题的方法(包括:再次下载 java 和 eclipse),但没有一个修复程序起作用。 i am asking for very specific and simplified help because i am new to this subject and i don't understand a lot.我要求非常具体和简化的帮助,因为我是这个主题的新手,我不太了解。

i get an error in the imports and in the chromedriver and webdriver.我在导入以及 chromedriver 和 webdriver 中遇到错误。

this is the code:这是代码:

package firstPackage;

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

public class FirstScript {

    public static void main(String[] args) {
        System.setProperty("Webdriver.Chrome.driver","/C:/Users/shale/Downloads/chromedriver_win321/chromedriver");

        WebDriver driver = new ChromeDriver();
        driver.get("http://www.google.com");

    }

}

here is the project with all of the selenium jars that i downloaded from their site here is where the chromedrivere.exe file is stored这是我从他们的网站下载的所有 selenium jar 的项目,这里是 chromedrivere.exe 文件的存储位置

输出

Can you change你能改变吗

System.setProperty("Webdriver.Chrome.driver","/C:/Users/shale/Downloads/chromedriver_win321/chromedriver");

to

System.setProperty("Webdriver.Chrome.driver","/C:/Users/shale/Downloads/chromedriver_win321/chromedriver.exe"); 

You are getting the error because you have not added the selenium dependencies to your classpath.您收到错误是因为您尚未将 selenium 依赖项添加到类路径中。

I strongly advice you to use a dependency management tool such as Maven or Gradle to do this.我强烈建议您使用依赖管理工具(例如 Maven 或 Gradle)来执行此操作。

However, if you would still want to add all the dependencies, then the following dependencies would be required (you may try to have only the chrome dependencies and give it a go)但是,如果您仍想添加所有依赖项,则需要以下依赖项(您可以尝试仅拥有 chrome 依赖项并试一试)

已解决的依赖关系

You should also change你也应该改变

System.setProperty("Webdriver.Chrome.driver","/C:/Users/shale/Downloads/chromedriver_win321/chromedriver");

to

System.setProperty("webdriver.chrome.driver","C:/Users/shale/Downloads/chromedriver_win321/chromedriver.exe");

(The case of the property matters). (财产的情况很重要)。

It should be System.setProperty("Webdriver.chrome.driver","/C:/Users/shale/Downloads/chromedriver_win321/chromedriver.exe");它应该是 System.setProperty("Webdriver.chrome.driver","/C:/Users/shale/Downloads/chromedriver_win321/chromedriver.exe"); in setProperty().在 setProperty() 中。

Also please add all the required jar files.另外请添加所有必需的 jar 文件。

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 . ...暗示WebDriverChromeDriver未在编译时解析。


Seems your imports are good to go.看来你的imports是好的。 However, as you are using OS you need to take care of a few things as follows:但是,当您使用操作系统时,您需要注意以下几点:

  • In the System.setProperty() line, you need to replace Webdriver.Chrome.driver with webdriver.chrome.driver .System.setProperty()行中,您需要将Webdriver.Chrome.driver替换为webdriver.chrome.driver
  • You need to provide the absolute path of the chromedriver removing the initial back slash ie / before C: .您需要提供chromedriver绝对路径,删除初始反斜杠ie /之前C:
  • You can also provide the absolute path of the chromedriver escaping the forward slash ie \\\\ .您还可以提供chromedriver转义正斜杠的绝对路径,即\\\\
  • You need to provide the extension of the chromedriver binary, ie exe .您需要提供chromedriver二进制文件的扩展名,即exe
  • So effectively, the line of code will be:如此有效,代码行将是:

     System.setProperty("webdriver.chrome.driver","C\\\\Users\\\\shale\\\\Downloads\\\\chromedriver_win321\\\\chromedriver.exe");

You can find a relevant discussion in java.lang.Error: Unresolved compilation problems : WebDriver/ChromeDriver cannot be resolved to a type error while executing selenium tests您可以在java.lang.Error: Unresolved compiler questions : WebDriver/ChromeDriver cannot beresolution to a type error while execution selenium tests 中找到相关讨论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java 16 ChromeDriver WebDriver 即使在执行所有必要步骤后也无法解析为类型 - Java 16 ChromeDriver WebDriver cannot be resolved to a type even after following all the necessary steps Webdriver无法解析为类型错误 - Webdriver cannot be resolved to a type error 类型不匹配:无法使用Java在Selenium Webdriver中从ChromeDriver转换为WebDriver - Type mismatch: cannot convert from ChromeDriver to WebDriver in selenium webdriver with java WebDriver无法解析为Selenium 3.5.3的类型 - WebDriver cannot be resolved to a type for Selenium 3.5.3 TakesScreenshot 无法解析为 Selenium WebDriver 中的类型 - TakesScreenshot cannot be resolved to a type in Selenium WebDriver Selenium webdriver: <WebElement> 迭代器无法解析为某种类型 - Selenium webdriver : <WebElement> Iterator cannot be resolved to a type Android WebDriver Java代码中的“ WebDriver无法解析为类型”错误 - “WebDriver cannot be resolved to a type” error in Android WebDriver java code 运行 Selenium webdriver 时“FirefoxDriver 无法解析为类型” - "FirefoxDriver cannot be resolved to a type" when running Selenium webdriver 无法解析/无法解析为类型 - Cannot be resolved / Cannot be resolved to a type Eclipse 上的“ChromeDriver/WebDriver can not be resoved to a type”错误 - "ChromeDriver/ WebDriver can not be resoved to a type" error on Eclipse
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM