"The import org cannot be resolved" error with the imports in Eclipse Photon with selenium Standalone server 3.9.1

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();
    }
}

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.

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

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

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.

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 :)

Comments
  • hard to say. do you have the latest versions of the needed jars? here and here
  • Can you kindly explain why is that?