Launching Chrome Browser using WebDriver
In WebDriver, We launch FireFox and Internet Explorer by using
WebDriver driver = new FirefoxDriver(); //this line would launch Firefox
WebDriver driver = new InternetExplorerDriver(); //this line would launch IE browser
WebDriver driver = new InternetExplorerDriver(); //this line would launch IE browser
But when we write below line like FireFox and IEWebDriver driver = new ChromeDriver();Then It throws Error and Here I am pasting Error Trace shown in Eclipsejava.lang.IllegalStateException: The path to the driver 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/chromedriver/downloads/list
at com.google.common.base.Preconditions.checkState(Preconditions.java:176)
IT seems rea
lly tedious na, But there is one way to resolve this Error and this could be done by using this
1- Download zip file of chromedriver for Windows from here 2- Unzip downloaded Chromedriver for Windows and find the absolute path of chromedriver.exe
3- Now set Property of System by using this line
System.setProperty(“webdriver.chorme.driver”,”E:\\DD MISHRA\\workspace\\chromedriver_win_26.0.1383.0\\chromedriver.exe”);
and after this line write your traditional line to launch the browser like this
WebDriver driver =new ChromeDriver();
3- Now set Property of System by using this line
System.setProperty(“webdriver.chorme.driver”,”E:\\DD MISHRA\\workspace\\chromedriver_win_26.0.1383.0\\chromedriver.exe”);
and after this line write your traditional line to launch the browser like this
WebDriver driver =new ChromeDriver();
So why not we write one script that help us to see the launching of Chrome
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Chrome {
WebDriver driver;
@Before
public void launchChrome()
{
System.setProperty("webdriver.chrome.driver", "E:\\DD MISHRA\\workspace\\chromedriver_win_26.0.1383.0\\chromedriver.exe");
driver = new ChromeDriver();
}
@Test
public void testChrome()
{
driver.get("http://www.google.co.in");
driver.findElement(By.id("gbqfq")).sendKeys("Selenium");
}
@After
public void kill()
{
driver.close();
driver.quit();
}
}
This code is verified at my own and if there is any suggestion then please let me know. I would be very happy to hear from you..