3

I'm creating a basic selenium Webdriver program by adding the selenium jars and relative jars, below is my code. but when i try to resolve firefordriver and webdriver for importing them. im getting "The import org cannot be resolved" error.

Environment details:

JavaSe-10.

Eclipse Version Photon Release (4.8.0) Build id: 20180619-1200

Selenium StandAlone server 3.9.1

Code:

package selenium;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class WebDriverBasics {

    public static void main(String[] args) {

        //1. Firefox browser. 
        //geckodriver.
        System.setProperty("webdriver.gecko.driver","d:\\installations\\eclipse\\jars\\geckodriver.exe");
        WebDriver driver = new FirefoxDriver();
    }
}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Rakesh
  • 118
  • 1
  • 9
  • hard to say. do you have the latest versions of the needed jars? [here](https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java) and [here](https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-firefox-driver) – Jack Flamp Aug 20 '18 at 10:20

5 Answers5

5

delete module-info.java file or any other module file that was created at the time of creating the project. That will resolve the issue.

module-info.java

error resolved

prashant.kr.mod
  • 1,178
  • 13
  • 28
  • 1
    Can you kindly explain why is that? – Line Jan 13 '19 at 20:49
  • 1
    @Line module-info.java need to be in the appropriate sub-directory. The .java files don't need to be on the classpath, but on the source path. (The generated .class files need to be on the classpath.) – prashant.kr.mod Jul 09 '20 at 12:10
0

Add selenium jars and other required jars to build path of your project in Eclipse and Rebuild the project.

Abhishek_Mishra
  • 4,551
  • 4
  • 25
  • 38
0

Add jars like this

Right click on project --> Configure BuildPath --> Java Build Path Libraries -->

Double click on JRE SYSTEM LIBRARY --> Then select alternate JRE

From C:\Program Files (x86)\Java\jre7\lib your path where you store JRE

Refer this answer

iamsankalp89
  • 4,607
  • 2
  • 15
  • 36
0

This error message...

The import org cannot be resolved

...implies that your program was unable to resolve the following imports:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

Your main issue for the imports not getting reslved is circular-dependency.

Though you have added all the selenium jars and relative jars but you have named the program Module / Package as selenium as follows:

package selenium;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

This is causing a circular-dependency hence the imports are not getting resolved through the selenium related jars.

Solution

Changing/Modifying the Module / Package name from selenium to something else, e.g. myProgram will solve the issue.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
-2

You have to remove the module-info.java class from project it will works. Module info is not required for selenium project. So you can remove it :)

Ramesh Korla
  • 64
  • 2
  • 3
  • 8