gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 07:34:28 25 4
gpt4 key购买 nike

这是我的代码:

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());
}
}

下面是声明 webdriver 概念后得到的错误消息:

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)

注意:我可以执行简单的java程序。

Screenshot of my Eclipse

最佳答案

这个错误信息...

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
WebDriver cannot be resolved to a type
ChromeDriver cannot be resolved to a type

...暗示 WebDriverChromeDriver 未在编译时 解析。

根据您分享的快照,您的主要问题是您的项目空间中存在多个类似的二进制文件,如下所示:

  • 您已将 selenium-server-standalone-3.11.0 添加为依赖项。
  • 此外,您还包含了来自 selenium-java-3.11.0Java 客户端 JAR 作为依赖项。

因此,您很可能已经从一个 JAR 资源(即 selenium-server-standalone-3.11.0selenium-java-3.11.0 JAR)但编译时类试图从其他 JAR 中解析.因此您会看到 java.lang.Error: Unresolved compilation problems

解决方案

  • 要么只保留 selenium-server-standalone-3.11.0 JAR 作为外部 JAR。
  • 或者只保留 selenium-java-3.11.0 JAR 作为外部 JAR。
  • 删除所有其他 Selenium Java 客户端 JAR
  • 清理您的项目工作区,通过您的IDE重建您的项目,仅使用所需的依赖项。
  • 系统重启
  • 执行你的@Test

关于eclipse - java.lang.错误 : Unresolved compilation problems : WebDriver/ChromeDriver cannot be resolved to a type error while executing selenium tests,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50111517/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com