java 无法解析 selenium 驱动程序的导入

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46904417/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 09:24:24  来源:igfitidea点击:

import cannot be resolved for selenium drivers

javaseleniumselenium-webdriverselenium-chromedriver

提问by VVB

I am trying to import WebDriver & ChromeDriver, tried all libraires but no luck

我正在尝试导入 WebDriver 和 ChromeDriver,尝试了所有库但没有运气

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

public class TestChrome {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.setProperty("webdriver.chrome.driver", "/home/vikas/Downloads/chromedriver.exe");

        // Initialize browser
        WebDriver driver=new ChromeDriver();


        // Open Google
        driver.get("http://www.google.com");

        // Maximize browser

        driver.manage().window().maximize();
    }

}

Getting below errors

获得以下错误

The import org.openqa.selenium.WebDriver cannot be resolved
The import org.openqa.selenium.chrome.ChromeDriver cannot be resolved

回答by Rathan Naik

selenium jar has to be added to the project to identify the interface org.openqa.selenium.WebDriverand class org.openqa.selenium.chrome.ChromeDriver

selenium jar 必须添加到项目中以识别接口org.openqa.selenium.WebDriver和类org.openqa.selenium.chrome.ChromeDriver

selenium download link: http://www.seleniumhq.org/download/

硒下载链接:http: //www.seleniumhq.org/download/

回答by Shubham Jain

You are working on Linux/Mac, as you have a path like /home/vikas/, but you are using chromedriver.exe.

您正在 Linux/Mac 上工作,因为您有类似 的路径/home/vikas/,但您使用的是 chromedriver.exe。

You can't use exe binary on Linux platform. It is specifically designed for Windows only, .exeis only for Windows.

您不能在 Linux 平台上使用 exe 二进制文件。它专为 Windows 设计,仅.exe适用于 Windows。

You need to download Linux/Mac chrome binary from below URL:

您需要从以下 URL 下载 Linux/Mac chrome 二进制文件:

https://chromedriver.storage.googleapis.com/index.html?path=2.33/

https://chromedriver.storage.googleapis.com/index.html?path=2.33/

回答by iamsankalp89

This is the issue unresolved dependency. I think you should to used selenium 3.4with chromedriver2.32 and chrome 60 browser

这是未解决的依赖问题。我认为您应该将selenium 3.4chromedriver2.32 和 chrome 60 浏览器一起使用

Also i guess uu are importing all the jar files

另外我猜你正在导入所有的 jar 文件

回答by Davide Patti

The recommended Selenium (and chromedriver) that you must to use depends on your Chrome Browser version.

您必须使用的推荐 Selenium(和 chromedriver)取决于您的 Chrome 浏览器版本。

If you are using the latest version of the Chrome Browser, you have to use the latest chromedriverand (is recommended to) import the Selenium 3.5 (or greater).

如果您使用的是最新版本的 Chrome 浏览器,则必须使用最新的 chromedriver并(建议)导入Selenium 3.5(或更高版本)

So, from selenium download, download your interested version and import the jar in your project.

因此,从selenium download下载您感兴趣的版本并在您的项目中导入 jar。

If is a maven project, you can simple add this dependency on your pom:

如果是一个 Maven 项目,你可以简单地在你的 pom 上添加这个依赖项:

       <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.6.0</version>
       </dependency>

Else download the .jar and import manually (find how to import a jar using your IDE).

否则,下载 .jar 并手动导入(了解如何使用 IDE 导入 jar)。

回答by Bhargavi Kommineni

If it is in mac, there should be problem in setProperty path. Instead of mentioning chromedriver.exe, you should give just chromedriver(as you should be seeing just chromedriver under Downloads).

如果是mac,应该是setProperty路径有问题。而不是提到 chromedriver.exe,你应该只提供 chromedriver(因为你应该在下载下只看到 chromedriver)。

Be sure to set JAVA_HOME path in bash profile.

请务必在 bash 配置文件中设置 JAVA_HOME 路径。

回答by Ranjit

Remove the selenium java jar files from Modulepath and add to Classpath

从 Modulepath 中删除 selenium java jar 文件并添加到 Classpath

回答by Ankur Vashisht

This error occurs due to unresolved dependency. can you confirm if all your jar dependencies are resolved

由于未解决的依赖关系而发生此错误。你能确认你所有的 jar 依赖项是否都解决了