“ChromeDriver/WebDriver无法解析为类型”错误在Eclipse上。

huangapple go评论132阅读模式
英文:

"ChromeDriver/ WebDriver can not be resoved to a type" error on Eclipse

问题

[openqa.selenium.WebDriver][1][openqa.selenium.chrome][2][openqa.selenium][3][项目结构][4][Java构建路径-> Jar文件][5]需要帮助!在Eclipse上使用Selenium和Java来操作Chrome浏览器。这是一个经常被问到的问题。我查阅了所有提供的解决方案,但是我的问题没有解决。

已经使用了最新版本:
Java: openjdk-15_windows-x64_bin
Eclipse: 适用于Java开发者
Selenium WebDriver Java客户端: selenium-java-3.141.59
Google Chrome版本: 86; 同版本的chromedriver_win32。

正在尝试实例化一个新的Chrome驱动:

已经将所有来自于'Selenium WebDriver Java客户端: selenium-java-3.141.59'的外部jar包添加到了项目的Java构建路径->库->添加外部Jars中。

我的代码:

```java
import org.openqa.selenium.By;  
import org.openqa.selenium.WebDriver;  
import org.openqa.selenium.chrome.ChromeDriver;
public class firstProgram {
public static void main(String[] args) {  
    
    WebDriver driver;		    
    System.setProperty("webdriver.chrome.driver", "D:\\ChromeDriver\\chromedriver.exe");  
    driver=new ChromeDriver();  
     
      
    }  
}

错误:

ChromeDriver无法解析为类型
WebDriver无法解析为类型

添加了导入语句后,所有三个的错误都相同。
import.org.---------- 无法解析。

请告诉我还需要做什么。我陷入了困境,无法继续。


<details>
<summary>英文:</summary>

[openqa.selenium.WebDriver][1][openqa.selenium.chrome][2][openqa.selenium][3][Project Structure][4][Java Build Path-&gt; Jar files][5]Need help! Using Selenium with Java for Chrome Browser on Eclipse.
It&#39;s a frequently asked question. Searched for all the solutions provided, but mine did not get resolved.

Have latest version:
Java: openjdk-15_windows-x64_bin
Eclipse: for Java Developers 
Selenium WebDriver Java client: selenium-java-3.141.59
Google Chrome version: 86; chromedriver_win32 of the same version.

Trying to instantiate a new chrome driver: 

Have added all the external jars coming from &#39;Selenium WebDriver Java client: selenium-java-3.141.59&#39; to my project Java Buildpath -&gt; Libraries -&gt; Add External Jars.

My code:
import org.openqa.selenium.By;  
import org.openqa.selenium.WebDriver;  
import org.openqa.selenium.chrome.ChromeDriver;
public class firstProgram {
public static void main(String[] args) {  
    
	WebDriver driver;		    
    System.setProperty(&quot;webdriver.chrome.driver&quot;, &quot;D:\\ChromeDriver\\chromedriver.exe&quot;);  
    driver=new ChromeDriver();  
 
   	      
    }  
}

Errors: 
ChromeDriver can not be resolved to a type
WebDriver can not be resolved to a type

After adding the import statements, same error for all the three.
The import.org.----------  can not be resolved.

Please let me know what else to be done. I&#39;m stuck, can not proceed.


  [1]: https://i.stack.imgur.com/JivNb.png
  [2]: https://i.stack.imgur.com/YuyDQ.png
  [3]: https://i.stack.imgur.com/rQcWG.png
  [4]: https://i.stack.imgur.com/pspsI.png
  [5]: https://i.stack.imgur.com/a0az2.png

</details>


# 答案1
**得分**: 0

按照@howlger的建议:“也许有另一个包含相同包的JAR文件。在这种情况下,您需要将JAR文件从模块路径移动到类路径。”

将JAR文件从模块路径移动到类路径后,错误被移除,我成功地打开了Chrome网页。

<details>
<summary>英文:</summary>

As @howlger suggested: &quot;Maybe there is another JAR that contains the same package. In this case, you have to move the JARs from the Modulepath to the Classpath.&quot;

Moving the JARs from Modulepath to Classpath removed the errors and I was able to open chrome webpage.

</details>



huangapple
  • 本文由 发表于 2020年10月8日 10:27:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/64254925.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定