问题
I am trying to import WebDriver & ChromeDriver, tried all libraires but no luck
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class TestChrome {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "/home/vikas/Downloads/chromedriver.exe");
// Initialize browser
WebDriver driver=new ChromeDriver();
// Open Google
driver.get("http://www.google.com");
// Maximize browser
driver.manage().window().maximize();
}
}
Getting below errors
The import org.openqa.selenium.WebDriver cannot be resolved
The import org.openqa.selenium.chrome.ChromeDriver cannot be resolved
回答1:
selenium jar has to be added to the project to identify the interface org.openqa.selenium.WebDriver and class org.openqa.selenium.chrome.ChromeDriver
selenium download link: http://www.seleniumhq.org/download/
回答2:
This error occurs due to unresolved dependency. can you confirm if all your jar dependencies are resolved
回答3:
This is the issue unresolved dependency. I think you should to used selenium 3.4 with chromedriver 2.32 and chrome 60 browser
Also i guess uu are importing all the jar files
回答4:
The recommended Selenium (and chromedriver) that you must to use depends on your Chrome Browser version.
If you are using the latest version of the Chrome Browser, you have to use the latest chromedriver and (is recommended to) import the Selenium 3.5 (or greater).
So, from selenium download, download your interested version and import the jar in your project.
If is a maven project, you can simple add this dependency on your pom:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.6.0</version>
</dependency>
Else download the .jar and import manually (find how to import a jar using your IDE).
回答5:
You are working on Linux/Mac, as you have a path like /home/vikas/, but you are using chromedriver.exe.
You can't use exe binary on Linux platform. It is specifically designed for Windows only, .exe is only for Windows.
You need to download Linux/Mac chrome binary from below URL:
https://chromedriver.storage.googleapis.com/index.html?path=2.33/
回答6:
If it is in mac, there should be problem in setProperty path. Instead of mentioning chromedriver.exe, you should give just chromedriver(as you should be seeing just chromedriver under Downloads).
Be sure to set JAVA_HOME path in bash profile.
来源:https://stackoverflow.com/questions/46904417/import-cannot-be-resolved-for-selenium-drivers