How to Start with Selenium Framework ? A simpler guide

Last updated on : Jun 15, 2023 by Shubham Srivastava

Have you decided to learn Selenium Automation Framework, but not sure How to start with Selenium framework ?

Congratulations !! You are on right place. In this tutorial, we are going to see, How can we start with Selenium framework, write and execute the automation scripts? We will also see, what installations, dependencies and tools we need to download / install as per your computer / laptop? And, a simple script that will automate the Google launch process.

Note** This in-depth Selenium tutorial is part of our free Selenium Framework Mastery Series. In case, if you are also interested to learn about other important topics of Selenium, then check the link after this Selenium guide.

Starting with Selenium Framework

1. Install an IDE – Eg. Eclipse / IntelliJ

The first thing that you require is an IDE, where you will be going to write down all your selenium test scripts. Nowadays, there are multiple options available depending upon what programming language you are choosing along with Selenium.

If you are not aware about the programming languages that supports Selenium, then here’s the detailed list –

  1. Java
  2. Python
  3. JavaScript
  4. Ruby
  5. C# (C Sharp)
  6. PHP*
  7. GO*
  8. Haskell*
  9. Perl*
  10. R*
  11. Dart*

* = In the above list, the Top 5 programming language are directly compatible with Selenium WebDriver / Selenium Grid, While other language bindings also exist and are supported by their own version of Selenium WebDriver (available in main project hosted on GitHub).

I would suggest to start with Eclipse IDE with any of the above programming language to work with Selenium Automation. Later, you can give a try to other IDEs as well, such as- IntelliJ / Atom / VS Code etc. To install Eclipse,

1.a Visit the Eclipse download page of their official website.

1.b Download Eclipse as per your operating system (Windows/Mac/Linux)

1.c Double click the downloaded file to initiate the installation process of Eclipse and follow the next steps of this guide.


2. Install IDE and Packages for selected programming language

After following above step 1 of downloading the IDE, the next step 2 is to download / install the required packages / development kits Or dependencies for the selected programming language.

Let’s say, you have decided to start writing selenium scripts with Java programming language, then you need to follow below steps to make sure Java is available in your system –

2.1 Visit the Java downloads official webpage by Oracle.

2.2 Login to website and download any LTS (Long Term Supported) Java JDK. Till date, below Java JDKs LTS date is published by the company –

  • Java JDK 8 through at least 2030.
  • Java JDK 11 through 2026.
  • Java JDK 17 through at least 2029.

2.3 Once you have downloaded the desired Java JDK, then just double click on it to initiate the installation process of it.

2.4 As the installation process of Java is completed, make sure to ADD its bin directory path location into your system’s environment variables.


3. Download Selenium to start writing automation scripts

Once you have done, both the above steps 1 & 2, then you need to download Selenium in your system and make it available for your project. Still if you did not understand why you need to download some package / files for Selenium, then here is your answer –

To create local Selenium WebDriver scripts, you need to make use of language-specific client drivers. Let’s say, you have selected Java as programming language to write automation scripts. You opened IDE –> then, created a Java project –> then, Created a .java file, written a public class with main (String args[]) method.

But, now you want to open any browser, let’s say – Chrome, then you need to write some Selenium script and Call Selenium class objects’ methods. So, for calling those Selenium methods, you will require Java based Selenium library available to your project. And for that, we need to download that library Or, include it in our project.

Below is where you can find the latest releases of all the Selenium components. You can also find a list of previous releases, source code, and additional information of dependencies if you using Maven in your project.

Here is, How to download selenium for a Java and Maven based project? Just follow below steps –

3.1 Visit the Selenium download official webpage.

Next, you can choose any one of the below points under section 3.2-a, b and c :

3.2.a If you want to work with Selenium Grid, then download the JAR file from mentioned latest stable version of it from Github link.

3.2.b In case, you want to work with Selenium WebDriver, then download the JAR file from mentioned latest stable version of it from Github link.

If you have followed any one from the above 2 steps 3.2.a or 3.2.b, then after downloading the file, just add the library to your project’s build path. Then only, the Selenium Library would be available to your project.

3.2.c In case, if your project is a Maven based project, then life is much easier for you. Just go to mvnrepository.com and search for ‘Selenium Java’ and click on the first link for Selenium WebDriver –> Copy its latest version dependency code –> Then, paste the copied dependency details into your project’s POM.xml file and Save. The maven will automatically do the below things for you –

  • Maven will download the mentioned dependency from official sources that you will mention in pom.xml file.
  • Maven will add the download libraries to your projects build path.
  • It will then build your project, to verify the compatibility.

So, once you installed the IDE, I’m assuming you have installed Eclipse IDE. Now follow these steps to execute your first Selenium sutomation script –

  1. Open Eclipse IDE –> Then, Go to ‘File’ –> ‘New’ –> ‘Maven project’ –> Enter any New name for your Project’s Artifact ID and Group ID.
  2. Once the Maven Project is created, Open it’s pom.xml file and copy-paste below dependencies from Line ___ to ___ :

File pom.xml –

<project xmlns="http://maven.apache.org/POM/4.0.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>sample</groupId>
	<artifactId>shubham.project</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<!-- Start Copying Below Dependencies -->
	<!--
	https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
	<dependencies>
		<dependency>
			<groupId>org.seleniumhq.selenium</groupId>
			<artifactId>selenium-java</artifactId>
			<version>4.9.1</version>
		</dependency>

		<!--
		https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-api -->
		<dependency>
			<groupId>org.seleniumhq.selenium</groupId>
			<artifactId>selenium-api</artifactId>
			<version>4.9.1</version>
		</dependency>
		
		<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
		<dependency>
		    <groupId>io.github.bonigarcia</groupId>
		    <artifactId>webdrivermanager</artifactId>
		    <version>5.3.3</version>
		</dependency>

	</dependencies>

	<!-- Copy till above line -->

</project>

4. Selenium WebDriver script for login page – First Script

So far, we have done all the required Installations and configuration. Now, we are good to go to write our first Selenium Script for Chrome Browser. Let’s first see the script and then try to decode it to understand – what are we writing here in code ?

// Include the required Classes from Selenium Library
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

// Include the required Class for Browser Driver Management 
import io.github.bonigarcia.wdm.WebDriverManager;

public class GoogleTranslateTest{
	
	public static void main(String[] args) throws Exception {
		
		
		// PRESETUP steps  -
		// Step 1- Download compatible browser driver binary file -
		WebDriverManager.chromedriver().setup();
		
		// Step 2- Initiate the desired browser driver object-
		WebDriver driver = new ChromeDriver();
		
		// Step 3- Delete all cookies- 
		driver.manage().deleteAllCookies();
		
		// Step 4- Maximize window - 
		driver.manage().window().maximize();
		

		// BUSINESS requirement steps -
		// Step 5- Go to WebPage -
		driver.get("https://translate.google.co.in/?sl=en&tl=hi&op=translate");
		
		// Step 6- Translate the Sentence -
		String sentence = "Learn Selenium with LogicalDuniya.com";
		
		// Step 7- Find the Input Box to input the Sentence for Translation - 
		WebElement inputTextBox = driver.findElement(By.xpath("//textarea[@aria-label='Source text']"));
		
		// Step 8- Input the Sentence for Translation-
		inputTextBox.clear();
		inputTextBox.sendKeys( sentence );
		
		// Step 9- Wait for 5 seconds to let the translation happen, then copy translated sentence -
		Thread.sleep( 15000 );
		WebElement resultBox = driver.findElement(By.xpath("//span[@class='HwtZe']"));
		
		String translatedTextResult = resultBox.getText();
		System.out.println("**** Result = \n"+ translatedTextResult);
		
		// Step 10- Close and Quit the Browser Driver -
		driver.close();
		driver.quit();
		
	}
}

Output –

Once you will trigger the above Selenium Script, it will successfully go to Google Translate, translates the given text, and prints the below translated result into your IDE’s console –

**** Result = 
Logicalduniya.com के साथ सेलेनियम सीखे

We have commented, what we have done in the above script step-by-step. Also, we have discussed in-depth & step-by-step about this script in this Selenium guide. Check that post, if you are interested or have any query.


Conclusion

In this post, we learnt How to set up Selenium framework?, How to start with Selenium Java? and How do I write my first Selenium program?

Hope your script would have been executed perfectly. If not, then just comment down the issue you are facing, We will take a look immediately.

This in-depth Selenium tutorial is part of our free Selenium Framework Mastery Series. In case, if you are also interested to learn about other important topics of Selenium, then check the link of Selenium Lessons.

Keep Thinking Logical..
Team LogicalDuniya.com
Cheers, Shubham !!

Shubham

Shubham Srivastava

Hey there, my name is Shubham and I'm working as an SDET at a US based FinTech company. I've more than 7 years of working experience and using my knowledge - I want make this platform super helpful for those, who want to solve any software development and testing related problems. Comment your query / request or suggestion in the below section, and I'll try to respond within 24 hours. Keep improving, Keep coding !!

Recommended Posts :


4.5 2 votes
Article Rating
Subscribe
Notify of
guest
4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

[…] (ToDo : Add permanent / published link of this post – LogicalDuniya | How to Start with Selenium Framework ? A simpler guide.) […]

[…] Selenium Drawbacks and Limitations – by LogicalDuniya.com […]

[…] Selenium version 3, we have multiple methods available to handle multiple browser windows and tabs related test […]

Press ESC to close