import org.openqa.selenium.firefox.FirefoxDriver;
public static void main (String[] args){
FirefoxDriver browser = new FirefoxDriver ();
browser.get("http://www.google.com");
}
Let's try the same format to open a Chrome browser
import org.openqa.selenium.chrome.ChromeDriver;
public static void main (String[] args){
ChromeDriver browser = new ChromeDriver ();
browser.get("http://www.google.com");
}
Once you run the code you will get an exception (I'm using Eclipse for compiling)
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
at com.google.common.base.Preconditions.checkState(Preconditions.java:199)
at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)
at org.openqa.selenium.chrome.ChromeDriverService.access$0(ChromeDriverService.java:1)
at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:116)
at chrome_test.main(chrome_test.java:8)
How to resolve this..?
- Go to https://sites.google.com/a/chromium.org/chromedriver/downloads
- Select the latest driver
- Download the .zip file for your operating system
- Unzip the file to your machine (anywhere u wish). This is a file named chromedriver.exe (lets think that I unzipped it at D:\Selenium)
- Now go back to code and add the following line (with your location of .exe file)
- Remember to modify path with double "\" as you can see below.
System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\chromedriver.exe");
Save and Run
It will work
FULL CODE
import org.openqa.selenium.chrome.ChromeDriver;
public class chrome_test {
public static void main (String[] args){
System.setProperty("webdriver.chrome.driver", "D:\\Selenium\\chromedriver.exe");
ChromeDriver browser = new ChromeDriver ();
browser.get("http://www.google.com");
}
}
 
not working in my case :(
ReplyDelete