WebDriverManager 无法解析导入 io.github

WebDriverManager The import io.github cannot be resolved

我在 pom.xml

中添加了以下 WebDriverManager maven 依赖项
<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>3.8.1</version>
    <scope>test</scope>
</dependency> 

在我的 java class 中,我无法导入 io.github.bonigarcia.wdm.WebDriverManager;自动地。如果手动编写导入,我会在 io.github 处收到错误消息:导入 io.github 无法解析。

这里有什么问题?我在 pom.xml.

中尝试了清理、重启和不同版本的 webdrivermanager

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>3.8.1</version>
    <scope>test</scope>
</dependency> 

您使用的依赖项减少为 <scope>test</scope>,但这究竟意味着什么? 表示编译不需要依赖,执行只需要依赖。

它出现在运行时和测试期间,但不出现在编译期间。

默认范围是compile。编译依赖项在项目的所有类路径中都可用。

编辑:

<scope>test</scope> 使依赖项可用于执行但不可用于编译。这是什么意思?

这意味着类路径可用于项目中的 src/test 文件夹。

默认范围使类路径可用于 src/mainsrc/test。因此,如果你让任何 类 管理 WebDriver 并将它们放在源文件夹下,你应该使用允许依赖项在编译时可用的范围。

        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>4.2.2</version>
        <scope>compile</scope>
    </dependency>

在scope replace with compile instead of test, it will import.*

你也可以不指定范围,它也会起作用:

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>4.4.3</version>
</dependency>

Windows 10 面向企业 Java 开发人员的 Eclipse IDE - 2020-12

Java JDK 15.0.2

行家 3.6.3