Selenium Installation Tutorial With Example

Why we should use Selenium for Automation Testing?

Being a Software Tester we hear much about Automation and Selenium so this tutorial is entry level of your Automation learning. Selenium is used for Website Automation and it helps to perform all the browser related operation. It can be used for clicking on web element, filling form, switching to different windows, mouse hover, drag and drop operations and many more including every complex operation of web application. So, if you are Software tester, QA (Quality Analyst or Quality Assurance Engineer) this tutorial will be a lot worth it.


In this tutorial, we will guide you to complete Selenium set up and also write first selenium project or script. This tutorial will be explaining each step with a clear snapshot which will help you to do this set up independently & with ease.

Pre Requisites for Selenium Framework:

  • Step 1: One Machine with 32 bit or 64 bit operating system and min RAM 4 GB
  • Step 2: Java should be Installed
  • Step 3: Eclipse or any other IDE should be installed on your machine (We will be using Eclipse for this tutorial)

Also Read: Selenium Interview Questions

How to check Java version in cmd?

Java should be installed on machine.
Steps to check Java Installation: Open command prompt and type “java -version” and enter.

java version in cmd

Note:

If java is not installed on your machine then and want to setup java then follow this tutorial- Step by Step Java Installation & Setup

Steps to Install Selenium in Windows:

  • Step 1: Go to Desktop and click on Eclipse icon to open eclipse
Eclipse
  • Step 2: Select workspace

Eclipse is already set up. Now, it will open it with default workspace but if you are opening eclipse ide for the first time it will ask for workspace. Then, you have to give one folder path as workspace.

Eclipse launcher

Create Selenium Java Project:

  • Step 3: Create Selenium Project (similar to Java Project):

Go to File> New and click on Java Project

Eclipse Java New Project
  • Step 4: Enter Project Details:

Enter Project Name, ensure correct JRE selected and click on Finish to create your Project.

New Java Project Details

Selenium Java Project has been created now.

Also Read: Katalon Studio and Selenium Detailed Comparison

Selenium roject navigation panel

Add Selenium Jar in Java Project:

  • Step 5: Download Selenium Jar:

Selenium is responsible for all the browser operations so you need to download from Selenium website. Although Selenium released different version we have to choose the latest stable version also our installed version should be compatible with selenium. Here are steps to download Chrome Driver.

  • Step 5.1: Go to selenium website https://www.selenium.dev/downloads/ and download the latest Jar and save on your machine.

Direct download link: https://bit.ly/2TlkRyu

Selenium Server Download
  • Step 5.2: Save on your machine
Save Selenium Jar
  • Step 6: Add Selenium Jar in your above Project- Configure and Build your project with Selenium Jar.
  • Step 6.1: Go to Eclipse and right-click on automation Project
  • Step 6.2: Move the mouse to “Build Path” and go and click on “Configure Build Path”. Refer below for hint:
Configure Build Path
  • Step 6.3: Browse above downloaded selenium jar (Step 5)
Selenium Jar
  • Step 6.4: Click on Open to add jar.
Add Jar
  • Step 6.5: Click on Apply and close. Now selenium jar added into your project.
Selenium Jar

Download Chrome Driver for Selenium:

  • Step 7: Download Chrome Driver as per your browser version:
  • Step 7.1: Check chrome version: Open Chrome and go to the right corner, click in three dots, navigate to “Help” ad click on “About Google Chrome” and check the browser version.
Chrome version
  • Step 7.2: Download Chrome Driver exe from below link and navigate to a new window and save Chrome Driver zip file on your machine:

https://chromedriver.chromium.org/downloads

Chrome driver version
  • Step 7.3: Save Chrome Driver zip file and then Unzip the file to a location
Chrome driver zip file
  • Step 8: Go to Project and right-click on the src folder and create a test package.
Create package
  • Step 9: Go to test package create LoginTest class
Create class

First Selenium Webdriver Script in Java:

  • Step 10: Write your first selenium test
package test;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class LoginTest {
	public static void main(String[] args) {
		// set system property with ChromeDriver
		System.setProperty("webdriver.chrome.driver", "C:\\Users\\ajit"
				+ "\\Desktop\\NewCode\\SeleniumJars\\chromedriver.exe");
		//Create WebDriver instance
		WebDriver driver = new ChromeDriver();
		// driver.get method used to naviagte to website
		driver.get("http://newtours.demoaut.com/");
		// maximize browser size
		driver.manage().window().maximize();
		//Print Website Title
		System.out.println("website title: "+driver.getTitle());
		// Close Browser
		driver.close();
		
	}
}
Selenium first test script
  • Step 11: Now the whole set up is done. Run your test and you will see browser will open and website printed on the console.

Console output:

Output

Also Read: Install Java & Setup Environment Variable

Congratulations!! your selenium set up has been done. Now, you can automate any website using selenium. Still if you face any issue in above steps then feel free to contact us. For more learning explore our other blogs. Also we are looking for your feedback and suggestions

0 0 vote
Article Rating
close

Subscribe to our Newsletter:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Open chat
Feel free to contact