0

I am trying to run a software in Eclipse but failed facing the following errors.

Exception in thread "main" java.lang.Error: Unresolved compilation problems: WebDriver cannot be resolved to a type ChromeDriver cannot be resolved to a type WebElement cannot be resolved to a type By cannot be resolved. Can anyone help me working this problem?

I am trying to open a website for testing purpose through selenium webdrive. The software I am working with are:

  • selenium 3.13.0
  • eclipse 4.12.0
  • javac 1.8.0_221
  • Chrome 77.0.3865.90 (Official Build) (64-bit)
package Cross_browser_test;

import org.openqa.selenium.*;
import org.openqa.selenium.chrome.*;

public class Facebook_Login {

    //public 

/**

* @param args

*/
       public static void main(String[] args) {

        // Optional. If not specified, WebDriver searches the PATH for chromedriver.
           WebDriver driver;

           System.setProperty("webdriver.chrome.driver", "C:\\webdriver\\cromedriver.exe");

            driver = new ChromeDriver();
            driver.get("http://www.google.com/");
            Thread.sleep(5000);  // Let the user actually see something!
            WebElement searchBox = driver.findElement(By.name("q"));
            searchBox.sendKeys("ChromeDriver");
            searchBox.submit();
            Thread.sleep(5000);  // Let the user actually see something!
            driver.quit();
          }

}
lczapski
  • 4,026
  • 3
  • 16
  • 32
Ghani
  • 1

1 Answers1

1

You do not have selenium libraries in your classpath. Hence compiler cannot resolve webdriver-related class names that you use in your code.

The solution is to add libraries to your class path. If you're using Maven to manage dependencies in your code, then add proper dependencies definition, otherwise download jar files where selenium libs are packed and add them to your eclipse project as external libs.

Alexey R.
  • 8,057
  • 2
  • 11
  • 27
  • Hi Alexxey! Thanks a lot for your advice. – Ghani Oct 10 '19 at 05:53
  • Hi Alexxey! Thanks a lot for your advice. I have put the selenium libraries in the classpath. The relevant errors have gone. But it encounters the Exception-Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: C:\webdriver\cromedriver.exe, though the right and latest available executable of the driver is placed in that location. I am using Google chrome Version 77.0.3865.90 (Official Build) (64-bit) in Win 10 machine. Thanks again. – Ghani Oct 10 '19 at 05:59
  • Hi! Check if your path to chromedriver is correct. I suspect you're missing `h` after `c`. Fix the path so that your cromedriver would become chromedriver. – Alexey R. Oct 10 '19 at 08:12
  • Putting the chromedriver in the directory C:\\Windows has resolved the problem and it works as expected. – Ghani Oct 10 '19 at 15:40
  • Hi Hi Alexxey! Putting the driver in C:\webdriver also works after correcting the spelling of chromedriver. Thanks. – Ghani Oct 10 '19 at 16:32