Search code examples
javaseleniumintellij-ideamaven-3

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


I'm following a tutorial about Selenium with Java. I had followed the instructions and add maven dependency:

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

Then run mvn install

But when I create the class "HomePage", with an import to org.openqa.selenium.By, IntelliJ saids: 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");
}

Any help would be appreciated!


Solution

  • Class org.openqa.selenium.By is defined in selenium-api, You need to add the following dependency to your project:

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

    Note that the version is not mandatory to 3.11.0—you can choose another version. For example, the one used by io.ddavison:conductor:1.1 is Selenium 2.43.1. You need to:

    • Declare the same version 2.43.1 in your pom.xml
    • Or update to a newer version of io.ddavison:conductor