Reputation: 23
I have previously created a project and I have imported it into Eclipse, but I also completely reinstalled my windows and saved that specific program. In that program, I am using Selenium and Chrome Webdriver. I installed them both and added the project into my library, but Eclipse won't allow me to import Selenium and because of that it is throwing numerous exceptions. I imported a list as well but that class seemed to work...
I have tried to import it like this:
import org.openqa.selenium.*;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;
However, Eclipse says: "the import org.openqa cannot be resolved"
Why is this happening and how can I resolve it?
Upvotes: 1
Views: 6593
Reputation: 42
First, If you are using maven or gradle, there is no need to Add jar file explicitly in Build path. This is sustainable solution compared to what you are planning because
create a new Maven Project and add below
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
If you are new to maven, you can refer below tutorial on how to create a maven project, then please refer below tutorial. it can explain how to create a project and add the dependencies.
https://www.youtube.com/watch?v=YyB2NGV69xE
Upvotes: 0
Reputation: 129
looks like you don't have the selenium jar in your class path. if you are using a maven project you can add this dependency in the pom
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
and if its a Non-Maven Project Download the library from here https://www.selenium.dev/downloads/ and set up the classpath
Project => Properties => Java Build Path => Libraries => Add JAR/Add External JAR
Upvotes: 0
Reputation: 3251
The issue here is that you do not have the org.openqa.selenium
library in your classpath, so eclipse does not know where to look to find it and load the contents for for features like code completion and highlighting.
To add the library jar edit the project settings: Project => Properties => Java Build Path => Libraries => Add JAR ...
You can read more here
Upvotes: 1