How to Launch Chrome Browser in Selenium

Profile picture for user devraj

To launch a chrome browser using selenium. First we need to download the chrome driver. 

Step1: Go to Help->About Google Chrome to check your browser version.

launch chrome browser in selenium

Step 2: Open this link or you can search in google by typing "download chromedriver"

Step 3: Click on the latest stable release if you have updated your browser to latest version otherwise click on the link which match your browser version.

selenium code to open chrome browser

Step 4: Here driver file is different for each operating system Windows exe will not work on Mac or Linux system. Once you will click on link, download will start.

how to launch a chrome browser in selenium

Step 5: Unzip and Paste downloaded file to drivers folder or directory of your choice.

Step 6: Now open your driver configuration file or class file and paste below code. Since we have not introduced TestNG or JUnit yet, we will be executing this with Java runner using main class.

Launch Chrome Browser in Selenium Java

package com.pb.seltest.util;

import org.openqa.selenium.WebDriver;

public class AppTest 
	public static void main(String args[])
		System.setProperty("",System.getProperty("user.dir") + "//drivers//chromedriver");
		WebDriver driver;
		driver = new ChromeDriver();

In above code,

  • setProperty basically sets the system property to a value named, and the path is mentioned to get the chrome driver. Here, usr.dir will get the current user working directory, and then we have added the chrome driver path.
  • WebDriver is the main interface for testing, representing an idealized web browser. The methods in the WebDriver interface fall into three categories: Control of the browser itself, Selection of WebElements, and Debugging aids.
  • new ChromeDriver(), Here we are creating an instance of ChromeDriver; Chrome Driver is a class that extends RemoteWebDriver class.
  • get() will load a new web page in the current browser window. This is done using an HTTP GET operation, and the method will block until the load is complete.