java.lang.Error:未解决的编译问题:执行硒测试时,WebDriver/ChromeDriver无法解决为类型错误 [英] java.lang.Error: Unresolved compilation problems : WebDriver/ChromeDriver cannot be resolved to a type error while executing selenium tests

查看:258
本文介绍了java.lang.Error:未解决的编译问题:执行硒测试时,WebDriver/ChromeDriver无法解决为类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

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概念后收到的错误消息:

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)

注意:我可以执行简单的Java程序.

Note: I can able to execute simple java program.

我的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

...表示 WebDriver ChromeDriver 编译时未被解析.

...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 :

  • 您已包含 selenium-server-standalone-3.11.0 作为依赖项.
  • 此外,您还包含了 selenium-java-3.11.0 中的 Java客户端JAR 作为依赖.
  • 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.

因此,很可能您已经从一个JAR资源(即 selenium-server-standalone-3.11.0 selenium-java-3.11.0 JAR),但是 compiletime 这些类正试图从其他JAR中解析.因此,您会看到 java.lang.Error:未解决的编译问题

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

  • 要么只保留 selenium-server-standalone-3.11.0 JAR作为外部JAR.
  • 或者仅将 selenium-java-3.11.0 JAR保留为外部JAR.
  • 删除所有其他 Selenium Java Client JAR .
  • 通过 IDE
  • 清理您的项目工作区重建您的项目,并且仅具有必需的依赖项.
  • 进行系统重启.
  • 执行您的@Test.
  • 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.

这篇关于java.lang.Error:未解决的编译问题:执行硒测试时,WebDriver/ChromeDriver无法解决为类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆