0

I know this is a very frequently asked question but i have tried so many fixes to this problem (including: downloading java and eclipse again) and none of the fixes worked. i am asking for very specific and simplified help because i am new to this subject and i don't understand a lot.

i get an error in the imports and in the chromedriver and webdriver.

this is the code:

package firstPackage;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class FirstScript {

    public static void main(String[] args) {
        System.setProperty("Webdriver.Chrome.driver","/C:/Users/shale/Downloads/chromedriver_win321/chromedriver");

        WebDriver driver = new ChromeDriver();
        driver.get("http://www.google.com");

    }

}

here is the project with all of the selenium jars that i downloaded from their site here is where the chromedrivere.exe file is stored

Output

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Yoni Kuki
  • 1
  • 1
  • 3

4 Answers4

0

Can you change

System.setProperty("Webdriver.Chrome.driver","/C:/Users/shale/Downloads/chromedriver_win321/chromedriver");

to

System.setProperty("Webdriver.Chrome.driver","/C:/Users/shale/Downloads/chromedriver_win321/chromedriver.exe"); 
MhmtMelek
  • 11
  • 2
0

You are getting the error because you have not added the selenium dependencies to your classpath.

I strongly advice you to use a dependency management tool such as Maven or Gradle to do this.

However, if you would still want to add all the dependencies, then the following dependencies would be required (you may try to have only the chrome dependencies and give it a go)

Resolved Dependencies

You should also change

System.setProperty("Webdriver.Chrome.driver","/C:/Users/shale/Downloads/chromedriver_win321/chromedriver");

to

System.setProperty("webdriver.chrome.driver","C:/Users/shale/Downloads/chromedriver_win321/chromedriver.exe");

(The case of the property matters).

Nitin
  • 1,279
  • 2
  • 10
  • 12
  • how can i add all the jar files? – Yoni Kuki Dec 09 '19 at 12:13
  • from where should i download? – Yoni Kuki Dec 09 '19 at 12:13
  • also, can you explain what do you mean by "Maven" and "Gardle" and what they do and how to get them and use them – Yoni Kuki Dec 09 '19 at 12:17
  • Answer to "What is Maven?" is already [here](https://stackoverflow.com/questions/13335351/what-does-maven-do-in-theory-and-in-practice-when-is-it-worth-to-use-it). Once you go through that, you would be able to understand where to add your dependencies so that the required classes are available. – Nitin Dec 10 '19 at 02:40
0

It should be System.setProperty("Webdriver.chrome.driver","/C:/Users/shale/Downloads/chromedriver_win321/chromedriver.exe"); in setProperty().

Also please add all the required jar files.

Dish
  • 117
  • 8
0

This error message...

Exception in thread "main" java.lang.Error: Unresolved compilation problems:
WebDriver cannot be resolved to a type
ChromeDriver cannot be resolved to a type

...implies that WebDriver and ChromeDriver wasn't resolved at compiletime.


Seems your imports are good to go. However, as you are using OS you need to take care of a few things as follows:

  • In the System.setProperty() line, you need to replace Webdriver.Chrome.driver with webdriver.chrome.driver.
  • You need to provide the absolute path of the chromedriver removing the initial back slash i.e. / before C:.
  • You can also provide the absolute path of the chromedriver escaping the forward slash i.e. \\.
  • You need to provide the extension of the chromedriver binary, i.e. exe.
  • So effectively, the line of code will be:

    System.setProperty("webdriver.chrome.driver","C\\Users\\shale\\Downloads\\chromedriver_win321\\chromedriver.exe");
    

You can find a relevant discussion in java.lang.Error: Unresolved compilation problems : WebDriver/ChromeDriver cannot be resolved to a type error while executing selenium tests

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