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();
}
}
Hi,
ReplyDeleteI am getting the following error while trying to instantiate chrome driver
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Driver info: driver.version: ChromeDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:111)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:115)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:161)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:107)
below is the code for chrome instatiation
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
System.setProperty("webdriver.chrome.driver","C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
WebDriver driver = new ChromeDriver();
can you please advice on this.
Thank you,
Uday