---
title: "Building our first Selenium Application"  
description: "In this article, we have shown how with an example on how to get started with using Selenium for automating web pages."  
author: "Sonali Desai"  
published: 2021-07-29  
canonical: https://www.mindstick.com/blog/298370/building-our-first-selenium-application  
category: "software engineering"  
tags: ["selenium", "selenium webdriver", "selenium rc", "selenium grid", "selenium server"]  
reading_time: 9 minutes  

---

# Building our first Selenium Application

### What is Selenium?

Selenium is a portable framework for web [application testing](https://answers.mindstick.com/qa/114551/what-tools-are-commonly-used-for-automating-mobile-application-testing) that was created by Jason Huggins in 2004. It gives you the tools you need to write practical tests without having to learn a [scripting language](https://www.mindstick.com/forum/156500/is-javascript-only-client-side-scripting-language). It also includes the Selenese domain-specific language, which can be used to write tests in Scala, Ruby, Python, PHP, Perl, Java, Groovy, C#, and other common [programming languages](https://www.mindstick.com/articles/12386/5-up-and-coming-programming-languages-to-know-about). Most modern web browsers, such as Google Chrome, Mozilla Firefox, Internet Explorer, Edge, Opera, Safari, and others, will run Selenium tests. It also works with a variety of [operating systems](https://www.mindstick.com/articles/332551/operating-systems-trends-and-innovations-in-2023), including Windows, Linux, and macOS. It is free and open-source software licensed under the Apache License 2.0.

There are **four major components** of Selenium discussed below:-

**Selenium IDE**: The Selenium Suite's key tool is the Selenium IDE. It is the simplest and most straightforward framework in the Selenium suite. It's available as a Chrome Extension and a Firefox Add-On. It's a web automation research platform that's free to use. Unlike Selenium WebDriver and RC, it does not require any programming logic to write test scripts.

**Selenium RC**: Selenium Remote Control (RC) is a Java-based server that accepts browser HTTP commands. In any [programming language](https://www.mindstick.com/articles/329035/5-most-in-demand-programming-languages-to-consider-for-your-app-development-in-2022), RC assists us in writing automated tests for a web application.

**Selenium WebDriver**: Selenium Webdriver is a collection of APIs for testing web applications that are available for free. The Selenium Webdriver tool is used to automate web application testing to ensure that it functions properly.

**Selenium Grid**: Selenium Grid is a Selenium Suite component that allows you to run multiple tests simultaneously across multiple browsers, operating systems, and computers.

## Our goal in this article:-

We are going to automate the login process in a simple website named “***zero.webappsecurity.com***”. We will be using Java as our programming language, Google Chrome browser as our browser, and Eclipse as our Integrated [Development Environment](https://www.mindstick.com/interview/34043/setting-up-a-development-environment-in-knockout) (IDE). The goal is to make readers familiar with the process of writing automation scripts for websites and to get them started with Selenium.

## Getting started up with the setup:-

First of all, we need to install the Eclipse IDE for writing our automation script. It can be downloaded from this link. Then, we need to download and unzip the Selenium server (Grid). This can be downloaded from this link.

![Building our first Selenium Application](https://www.mindstick.com/blogs/83427443-a162-417e-8334-fd5b5d3f598d/images/3dfe77ce-eab9-4f7d-8847-79a424f7e0bf.png)\

Then, we need to download and unzip Selenium Client and Webdriver Bindings for Java language from the same link.

![Building our first Selenium Application](https://www.mindstick.com/blogs/83427443-a162-417e-8334-fd5b5d3f598d/images/5ba4314a-86f5-4b64-bd5a-ea247fa9931f.png)\

We need to download and unzip the ChromeDriver as well from this link.

![Building our first Selenium Application](https://www.mindstick.com/blogs/83427443-a162-417e-8334-fd5b5d3f598d/images/db117e71-d45d-45e0-a0c3-a400b5375b89.png)\

## Getting started with the automation script:-

Open the Eclipse editor. There, create a new Java project from File => New Java Project. We will be naming our project **Selenium**.

![Building our first Selenium Application](https://www.mindstick.com/blogs/83427443-a162-417e-8334-fd5b5d3f598d/images/5f485241-6669-486b-9a77-9183362b1f16.png)\

After that, we create a new package named ***SeleniumPackage*** inside this project.

![Building our first Selenium Application](https://www.mindstick.com/blogs/83427443-a162-417e-8334-fd5b5d3f598d/images/ed1c1f4d-0312-4eec-a97c-bf58f2135324.png)\

After that, we create a class named ***LoginScript***.

![Building our first Selenium Application](https://www.mindstick.com/blogs/83427443-a162-417e-8334-fd5b5d3f598d/images/49b88523-ea2b-4e73-8a8d-56c8b0cddeb8.png)\

Next, we right click on the **JRE System Library** under **Package Explorer** and click on **Build Path => Configure Build Path**.

![Building our first Selenium Application](https://www.mindstick.com/blogs/83427443-a162-417e-8334-fd5b5d3f598d/images/95358054-49b7-4e98-8204-cca142249f9e.png)\

Next, we head over to the Classpath and click on **Add External Jars**... We browse through our system and add our downloaded and unzipped **Selenium Standalone Server Jar** file to it.

![Building our first Selenium Application](https://www.mindstick.com/blogs/83427443-a162-417e-8334-fd5b5d3f598d/images/5312caf2-b2df-4cbd-a668-1d287c0d9adf.png)\

We click on **Apply and close** now.

Now, we start with our script named **LoginScript**. We declare a main function inside the class. Inside the main function, the very first thing that we will do is to define the path to the chrome executable that we had downloaded earlier. We do it with the following line of code:-

## System.setProperty('webdriver.chrome.driver', {Path to the executable file} );

Next, we create an instance of the ChromeDriver. This can be done from the following line of code:-

## WebDriver driver = new ChromeDriver();

We see that there are errors in this line. The word WebDriver and ChromeDriver are underlined with red lines.

![Building our first Selenium Application](https://www.mindstick.com/blogs/83427443-a162-417e-8334-fd5b5d3f598d/images/2d4869c0-537d-41cb-ada6-086d8c6e0d6c.png)\

This is because we need to import WebDriver and ChromeDriver into our script. This can be done by hovering over these words and selecting the import option. This includes the following pieces of code into our script:-

## import org.openqa.selenium.WebDriver;

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

Next, we use the **get( )** method of the driver object so as to open our required web page. This can be done with the following code:-

## driver.get('http://zero.webappsecurity.com/');

We maximize the browser window by the following code:-

## driver.manage().window().maximize();

We run the script until now to see where we are currently. We see the following output on our browser:-

![Building our first Selenium Application](https://www.mindstick.com/blogs/83427443-a162-417e-8334-fd5b5d3f598d/images/86c3b5f8-b1ca-47f3-aab9-b898012ddd8b.png)\

We write code to set a timeout for loading the web page. If the web page does not get loaded in this time frame, an exception will be thrown. The following code is used :-

## driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);

Now we write code to implicitly wait for twenty seconds. If the element is not found within 20 seconds, an exception will be thrown. This can be done by the following code:-

## driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

For this to work, we need to import the following:-

## import java.util.concurrent.TimeUnit;

Now, we write code so that the sign-in [button is clicked](https://www.mindstick.com/forum/157821/write-a-jquery-code-that-selects-all-the-checkboxes-in-a-form-when-a-select-all-button-is-clicked). We first inspected the web page and found that the sign-in button has an id of “**signin_button**”.

![Building our first Selenium Application](https://www.mindstick.com/blogs/83427443-a162-417e-8334-fd5b5d3f598d/images/d21d808f-486f-4b87-b13e-644796291cd4.png)\

The automation of clicking sign-in button is done by the following code:-

## driver.findElement(By.id('signin_button')).click();

On running our script now, we see that we have successfully been redirected to the login page.

We again write code to set a timeout for loading the web page. If the web page does not get loaded in this time frame, an exception will be thrown. The following code is used:-

## driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);

Now we write code to implicitly wait for twenty seconds. If the element is not found within 20 seconds, an exception will be thrown. This can be done by the following code:-

## driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); \

Next, we inspect the input fields for the [username and password](https://www.mindstick.com/forum/160407/how-does-a-bearer-token-differ-from-other-authentication-methods-such-as-username-and-password). We find that they have ids “**user_login**” and “**user_password**” respectively. Similarly, they have names as “**user_login**” and “**user_password**” respectively.\

![Building our first Selenium Application](https://www.mindstick.com/blogs/83427443-a162-417e-8334-fd5b5d3f598d/images/b09131a1-da8b-4778-90c4-d96db7056993.png)

So, we write code to find elements with this name and then fill in the details. From the site, we can infer that the correct login credentials are username: **username** and password: **password.**

![Building our first Selenium Application](https://www.mindstick.com/blogs/83427443-a162-417e-8334-fd5b5d3f598d/images/ec0cad4a-89c5-4ce7-926e-f5ef39ff1cf6.png) **\**

We can fill in the login credentials using the following code:-

## WebElement username_Input = driver.findElement(By.name('user_login'));

## username_Input.sendKeys('username');

## WebElement username_Password = driver.findElement(By.name('user_password'));

## username_Password.sendKeys('password');

We need to import the following to run the above code :-

## import org.openqa.selenium.WebElement;

Now we need to click the Sign in button, once the credentials have been filled in. We first inspect the Sign in button.

![Building our first Selenium Application](https://www.mindstick.com/blogs/83427443-a162-417e-8334-fd5b5d3f598d/images/84c42a6d-8b92-46cb-a885-78fad7269ba9.png)

The code for automating the clicking of Sign in button is:-

## driver.findElement(By.name('submit')).click();

We now run the script once again. We get the following output:-

![Building our first Selenium Application](https://www.mindstick.com/blogs/83427443-a162-417e-8334-fd5b5d3f598d/images/4d8eb283-fe45-4701-8d06-cc77bf503fe8.png)

We need to click on **Advanced** and then click on **Proceed to zero.webappsecurity.com**. We need to automate this process. First, we inspect the **Advanced** button.

![Building our first Selenium Application](https://www.mindstick.com/blogs/83427443-a162-417e-8334-fd5b5d3f598d/images/955a136d-2c1e-42ca-b86f-37b00f563a49.png)

As we can see, it has an id of **details-button**. Similarly, we inspect the Proceed link.

![Building our first Selenium Application](https://www.mindstick.com/blogs/83427443-a162-417e-8334-fd5b5d3f598d/images/cb3aa237-0af6-4894-bafa-be88fb4085cf.png)

We can clearly see that it has an id “**proceed-link**”. Now we write code to automate the process of clicking advanced and then the proceed link. This is done by the following snippet :-

## driver.findElement(By.id('details-button')).click();

## driver.findElement(By.id('proceed-link')).click();

On running this script, we get to see the following page as the final page:-\

![Building our first Selenium Application](https://www.mindstick.com/blogs/83427443-a162-417e-8334-fd5b5d3f598d/images/205baffe-6532-4a4e-890b-e883d7db96b3.png)

So, we have successfully logged in. We can write more code to playaround with the website. For example, you can write code to automate the process of logging out from this website. For this, you need to first find the element having “**username**” as its name and then click on it. Then, you need to find the element having “**Log out**” as its name from the drop-down and click it.

## The Complete Code :-

```
package SeleniumPackage;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class LoginScript {
 public static void main(String args[])
 {
  System.setProperty('webdriver.chrome.driver', 'C:\\Users\\user\\Downloads\\selenium\\chromedriver_win32\\chromedriver.exe');
  WebDriver driver = new ChromeDriver();
  driver.get('http://zero.webappsecurity.com/');
  driver.manage().window().maximize();
  driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
  driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
  driver.findElement(By.id('signin_button')).click();
  driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
  driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
  WebElement username_Input = driver.findElement(By.name('user_login'));
  username_Input.sendKeys('username');
  WebElement username_Password = driver.findElement(By.name('user_password'));
  username_Password.sendKeys('password');
  driver.findElement(By.name('submit')).click();
  driver.findElement(By.id('details-button')).click();
  driver.findElement(By.id('proceed-link')).click();
 }
}
```

## Conclusion:-

On the market, Selenium testers are in high demand. Since Selenium is becoming more common, the demand for Selenium testers is also growing. Testing repeated test scenarios on each and every new build takes almost no time at all with Selenium. As a consequence, the workload of the tester is reduced. It enables the tester to operate on several test scenarios at once. Due to machine overhead (performance) or lack of functionality, other methods do not have the luxury of parallel and distributed testing, which can be a major factor in persuading you to learn Selenium. In the sector, it is critical to complete tests quickly and efficiently.

In this article, we have shown how with an example on how to get started with using Selenium for automating web pages. It is only with practice that you can understand it better. Make sure to try your hands on some more websites and play around with them. This will strengthen your confidence in using Selenium. Remember Practice makes a man perfect. So, keep practicing and you will excel as an automation tester.

---

Original Source: https://www.mindstick.com/blog/298370/building-our-first-selenium-application

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
