Skip to main content

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

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

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

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.

download chrome

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.

download chrome for operating system

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

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

package com.pb.seltest.util;

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

public class AppTest 
{
	public static void main(String args[])
	{
		System.setProperty("webdriver.chrome.driver",System.getProperty("user.dir") + "//drivers//chromedriver");
		
		WebDriver driver;
		driver = new ChromeDriver();
		driver.get("http://www.automationpractice.com");
	}
}

In above code,

  • setProperty basically sets the system property to value named webdriver.chrome.driver 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 chrome driver path.
  • Here WebDriver is the main interface to use for testing, which represents an idealised web browser. The methods in WebDriver interface fall into three categories: Control of the browser itself, Selection of WebElements and Debugging aids
  • new ChromeDriver(), Here we are creating instance of ChromeDriver, Chrome Driver is a class which 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.
Video Tutorial

About

Elix is a premium wordpress theme for portfolio, freelancer, design agencies and a wide range of other design institutions.