尽管添加了 maven 依赖项,但未找到导入 org.openqa.selenium.By

import org.openqa.selenium.By not found despite of maven dependency has been added

我正在关注 tutorial about Selenium with Java。我已经按照说明添加了 Maven 依赖项:

<dependency>
     <groupId>io.ddavison</groupId>
     <artifactId>conductor</artifactId>
     <version>1.1</version>
</dependency>

然后运行mvn install

但是当我创建 class "HomePage" 并导入到 org.openqa.selenium.By 时,IntelliJ 说:Cannot resolve symbol 'openqa'

package com.mysite.selenium;

import org.openqa.selenium.By;

public class HomePage {
    // the tabs
    public static final String LOC_LNK_PROJECTSTAB = "li#menu_projects a[href$='projects/']";
    public static final String LOC_LNK_DOWNLOADTAB = "li#menu_download a[href$='download/']";
    public static final By LOC_LNK_DOCUMENTATIONTAB = By.xpath("//li[@id='menu_documentation']/a[contains(@href, 'docs/')]");
    public static final String LOC_LNK_SUPPORTTAB = "li#menu_support a[href$='support/']";
    public static final String LOC_LNK_ABOUTTAB = "li#menu_about a[href$='about/']";

    // download link
    public static final By LOC_LNK_DOWNLOADSELENIUM = By.linkText("Download Selenium");
}

如有任何帮助,我们将不胜感激!

Class org.openqa.selenium.By定义在selenium-api,你需要在你的项目中添加如下依赖:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-api</artifactId>
    <version>3.11.0</version>
</dependency>

请注意,3.11.0版本不是必须的——您可以选择其他版本。例如io.ddavison:conductor:1.1使用的是Selenium 2.43.1。您需要:

  • 在您的 pom.xml
  • 中声明相同的版本 2.43.1
  • 或更新到较新版本的 io.ddavison:conductor