Pages

Showing posts with label Chrome Driver settings. Show all posts
Showing posts with label Chrome Driver settings. Show all posts

Tuesday, 14 February 2012

Why I am getting "java.lang.IllegalStateException" while instantiating Chrome driver?

Sample error log:


Exception in thread "main" java.lang.IllegalStateException: The path to the chromedriver executable must be set by the webdriver.chrome.driver system property; for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://code.google.com/p/chromium/downloads/list
    at com.google.common.base.Preconditions.checkState(Preconditions.java:172)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:103)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:86)
    at tests.ChromeTest.main(ChromeTest.java:29)


To solve this problem, you have to set chromedriver executable path by the “webdriver.chrome.driver” system property.


That is, in java you can set that as below:


System.setProperty("webdriver.chrome.driver","C:\path\to\<<chromedriver_win_...>>\chromedriver.exe");

// Then Instantiate the ChromeDriver
WebDriver driver = new ChromeDriver();

Note - You can download latest ChromeDriver binary from here

Wednesday, 8 February 2012

How can I instantiate ChromeDriver?

The ChromeDriver can be instantiated as below:


WebDriver driver = new ChromeDriver(); // Instantiate the class - org.openqa.selenium.chrome.ChromeDriver

Sample code(Java Binding - Windows):


package tests;

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

public class ChromeDriverSample {

public static void main(String[] argv) throws Exception {

// For ChomeDriver, Need to Set 'webdriver.chrome.driver' property; if Chrome server binary (chromedriver.exe) file
//path is not mentioned in 'PATH'

//Download latest ChromeDriver binary from here and Set the 'webdriver.chrome.driver' property as below:

System.setProperty("webdriver.chrome.driver","C:\path\to\<<chromedriver_win_...>>\chromedriver.exe");

// Instantiate the ChromeDriver
WebDriver driver = new ChromeDriver();

// Visit the Selenium-WebDriver FAQ site
driver.get("http://seleniumwebdriverfaq.tumblr.com/");

// Print the title of the page - It should print "Selenium-WebDriver FAQ's"
System.out.println("Title of the page is: " + driver.getTitle());

//Close the browser window
driver.close();

//Quit the driver
driver.quit();
}
}