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
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");
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)
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).
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.
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 windows OS you need to take care of a few things as follows:
System.setProperty()
line, you need to replace Webdriver.Chrome.driver
with webdriver.chrome.driver
./
before C:
.\\\\
.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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.