[英]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 . ...暗示WebDriver和ChromeDriver未在编译时解析。
Seems your imports
are good to go.看来你的
imports
是好的。 However, as you are using windows OS you need to take care of a few things as follows:但是,当您使用Windows操作系统时,您需要注意以下几点:
System.setProperty()
line, you need to replace Webdriver.Chrome.driver
with webdriver.chrome.driver
.System.setProperty()
行中,您需要将Webdriver.Chrome.driver
替换为webdriver.chrome.driver
。/
before C:
./
之前C:
。\\\\
.\\\\
。exe
.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.