Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Setup of selenium project and How to open a chrome browser – Make Selenium Easy

Posted on 03/11/2020 By admin

In last post, we have done installation of JAVA and Eclipse. We have downloaded Selenium standalone jar file as well. Now, we will learn

  1. Setup of a java project in eclipse with selenium.
  2. Opening a chrome browser and perform some basic actions.

First we do little setup of eclipse.

Step 1: Create a folder(work space in terms of eclipse) in your local system and name it say “MakeSeleniumEasyLearnings”.

Step 2: Open Eclipse. It will ask for location of work space. Select the location of newly created work space in step 1. After completing of step 2, you will get eclipse window as below. You can notice work space name in eclipse header.

Step 3: Navigate to File->New->Project…

Step 4: Select Java Project and click on Next.

Step 5: Give the project name and click on Finish. Note here that even you have installed JDK 8 , but you can easily select any JRE version to work for. It is required when any java program has been developed using old versions of java and for better result, you want to execute with properly supported java version only. You can change java version form here any time.

Step 6: Now expand the project. Do right click on src and navigate to New->Package.

Step 7: Give package name as “browserExamples” and click on Finish. You will see a package is created under source.

Concept: Package is used in Java to group related classes.

Step 8: Do right click on project and navigate to New->Folder. And give the folder name as jarfiles.

Step 9: Copy the “selenium-server-standalone-3.3.1.jar” which we have downloaded and paste it by right clicking on jarfiles folder.

Step 10: Since, we have added an external jar files. So to work with it, we must add this jar file to java build path. We can do this by right click on jar file -> Build Path- > Add to build path.

You will notice after adding in to build path, selenium jar file will be shown under Referenced libraries.

So, above steps are required to run out first selenium script.

We know, selenium automates browser. So first step should be opening a browser. In this post, now we will learn:

  1. How to open Google Chrome browser.
  2. Open a URL which is used mostly to check internet connection is working or not. :-p
  3. Close the browser.

Let’s start:

Step 1: Right click on package named “browserExample” and navigate to New->Class. Give the class name as “OpeningChromeBrowser”. Check the check box of “public static void main(String args[]). Click on Finish.

Step 2:

Concept:

  1. Selenium provides a driver class for each browser to allow programmer to work on it. For example, for chrome we have chrome driver, firefox driver for firefox etc. So, to open a browser we need to use that browser driver class. Here we need to open chrome browser so we will use chrome driver.
  2. Every browser driver is a class and when we create an object of that driver class, it will open that browser window during execution.
  3. We create an object of a class using new keyword with constructor.
  4. Execution of java program starts from main method.
  5. We use semicolon to end a java statement.

Now write below code inside main method:

ChromeDriver driver = new ChromeDriver();

When you write this statement, you will get red lines on ChromeDriver. It is because, we have not imported the class from package. To do so, just mouse hover on ChromeDriver and select import from as shown below:

Step 3:

Concept:

  1. To open any URL, we use a method called get(String url).
  2. Pass URL with http or https otherwise you will get exception.(Will discuss later).

Now write below code:

driver.get(“https://www.google.com”);

Step 4:

Concept:

  1. We need to close the browser after opening URL. For this we can use close() or quit() methods. As of now, we will use quit() method. Difference between these two, we will learn later.

Now write below line of code:

driver.quit();

So final code after step 3 will be as below:

package browserExamples;

import org.openqa.selenium.chrome.ChromeDriver;

public class OpeningChromeBrowser {

public static void main(String[] args) {

ChromeDriver driver = new ChromeDriver(); driver.get(“https://www.google.com”);

driver.close();

}

}

Step 4: Run the java program. Right click on program and navigate to Run As-> Java Application. We are expecting that our program will perform desired operations.

But ye kya ho gya??? It is giving Exception.

Exception is:

Exception in thread “main” java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html at com.google.common.base.Preconditions.checkState(Preconditions.java:738) at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:111) at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32) at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137) at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:302) at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88) at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:124)

at browserExamples.OpeningChromeBrowser.main(OpeningChromeBrowser.java:9)

Solution of handling above exception:

I hope, you remember architecture of selenium webdriver. A java program can not directly communicate to a browser. It needs executable file(driver as explained in selenium architecture)  of that browser. Browser executable file is given by browser itself. You just need to download it and use it. Solution of above exception is given in exception only.

The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html

Go to URL http://chromedriver.storage.googleapis.com/index.html and download latest version of chrome executable file. Note here that executable file is also platform dependent. So download correct file. I will download for windows. Chrome executable file will work for both 32 bits and 64 bits machine.

It will be in zip format. You need to extract it to get .exe file.

Now, Do right click on project and navigate to New->Folder. And give the folder name as exefiles. Note here I am using folder system to categorized files. It is be useful while developing framework.

Now copy the chromedriver.exe file and paste in to exefiles folder.

Next, as per above exception, we need to set system property as well which can be done using below line of code:

System.setProperty(“webdriver.chrome.driver”, “./exefiles/chromedriver.exe”);

Concept:

  1. System is a java class.
  2. setProperty is a method which can be used to set property value at system level. It works as key value pair.
  3. Key you can see in exception you got above. generally it is “webdriver..driver.
  4. Value is path of browser executable. You can give relative or absolute path .

We are done now. Run the program and see kuch hota bhi hai ki ni abki baar.

Yes!! We did this time. I ran first time without setting property to make you understand the  architecture of selenium webdriver. Whenever you will get this exception in future, you can figure out your mistake quickly.

It is a very long post, but I hope you would have understand well. Kindly comment or mail me if you face any problem or have any suggestion to improve quality of my posts.

Thank you.

View all posts by Amod Mahajan

Uncategorized

Post navigation

Previous Post: DownloadLocationChrome – Make Selenium Easy
Next Post: loadurlOutput – Make Selenium Easy

Related Posts

Test Your Basics of Selenium WebDriver – Java By Answering These Interview Questions Uncategorized
image – Make Selenium Easy Uncategorized
IMG_4440 – Make Selenium Easy Uncategorized
April 15, 2017 – Make Selenium Easy Uncategorized
AllSubPakProject – Make Selenium Easy Uncategorized
REST Assured Tutorial 70 – Compare JSON Objects using JSONassert Library Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark