I'm trying to install and run Selenium (Java) on RedHat 8, using Eclipse. This is my first day with both Java and Maven (I normally do C++), and things are going pretty much as expected: it's not working, and I'm getting package org.openqa.selenium is not visible when I run the Maven build.
I'm going through the instructions at selenium.dev. This suggests installing the libraries with Maven:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.X</version>
</dependency>
and the example Java code is:
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;
import java.time.Duration;
public class HelloSelenium {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
try {
driver.get("https://google.com/ncr");
driver.findElement(By.name("q")).sendKeys("cheese" + Keys.ENTER);
WebElement firstResult = wait.until(presenceOfElementLocated(By.cssSelector("h3")));
System.out.println(firstResult.getAttribute("textContent"));
} finally {
driver.quit();
}
}
}
I've also installed geckodriver for FireFox, and this is in the path when I run eclipse.
The first problem was that version '3.X' isn't a thing, and I've replaced it with 3.9.1. The second is the message above ('package org.openqa.selenium is not visible'). There are lots of hits on the web, and this SO answer says that I also need selenium-api, but this isn't working for me. My current pom.xml has these dependencies:
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.9.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.9.1</version>
</dependency>
</dependencies>
My ~/.m2/repository/org/seleniumhq/selenium contains, I think, everything I'd expect to see from these dependencies. I've also tried adding a dependency on various levels below org.openqa.selenium, but it doesn't help.
Any ideas on how I can fix this? Thanks.