Sunday, 27 October 2013

How to launch chrome browser using selenium webdriver in Java?

Some important links related to ChromDriver

  1. Download chromedriver at
  2. Release information of ChromeDriver at 

Desired Capabilities of ChromeDriver
Chrome can be configured in various ways as mentioned by Google developer.

ChromeOptions options = new ChromeOptions();

//using chrome binary from specific location

//Setting the chrome profile

//to disable pop up blocking

//To start chrome without security warning

//To start the chrome in Maximized mode

//Setting custom options
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
options.setExperimentalOption("prefs", prefs);

//Adding extensions to chrome
options.addExtensions(new File("/path/to/extension.crx"));

We can directly pass the options to driver as shown below

driver = new ChromeDriver(options);

Or we can also set the capabilities as shown below

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);

Mobile emulation using ChromeDriver
You can start the chrome in mobile emulation mode by passing below capabilities.Please note that you can pass any device name as shown in chrome developer tools.

Map<String, String> mobileEmulation = new HashMap<String, String>();
mobileEmulation.put("deviceName", "Google Nexus 7");

Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("mobileEmulation", mobileEmulation);

Using RemoteWebDriver and ChromeDriver

You can start the chromedriver as shown below.
$ ./chromedriver
Started ChromeDriver

Then you can use below code to instantiate the driver.

WebDriver driver = new RemoteWebDriver("",;

ChromeDriver Example

You can use below example/code to start the new chrome session in Java using selenium web driver.

package seleniumtest;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;

public  class MainTest {
       public static void main(String[] args) {
                 WebDriver driver =null;
                 System.setProperty("", "F:\\selenium\\csharp\\chromedriver.exe");
                 driver = new ChromeDriver();
                 driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
                 driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
              }catch(Exception e){

Please note that we need to set the system property
We have to give the path of chromedriver exe

Once you have created driver object, you can use its methods to automated the browser tasks.

You may also like to read below topics.
  1. Press key in Selenium Webdriver in Java
  2. Read Table Data in Selenium Webdriver in Java
  3. Take the screenshot in Selenium Webdriver in Java
  4. Execute JavaScript in Selenium Webdriver in Java
  5. Handle multiple browser windows in Selenium Webdriver in Java
  6. Double-Click on the Element in Selenium Webdriver in Java
  7. Exceptions in Selenium Webdriver in Java
  8. Synchronization in Selenium Webdriver in Java
What do you think on above selenium topic. Please provide your inputs and comments. Thanks

No comments:

Post a Comment

Buy Best Selenium Books