Selenium Elements

Click to rate this post!
[Total: 0 Average: 0]

What is a web element?

Anything present on the web is called the Web element. This includes the text boxes, buttons, links etc.  So before performing any action in selenium,  we can easily identify the selenium element characteristics. This provides an API to find elements and take actions like entering the text into test boxes, Clicking the buttons etc.

Every webpage element will have attributes. Elements have more than one attribute. And these elements will have mostly unique attributes for different elements.  Moreover, these elements can have the same value for the class name.  For instance, consider a page containing two elements named image and text box. These elements do have the NAME  attribute and ID attribute. And these values need to be unique for each element. So we use locators to identify the webpage elements.

Find element():

Find element() identifies the web page elements .This element identifies the web elements lists on the web page.  And there are multiple ways to uniquely identify the web elements in a page such as ID, Name, Class Name, Link Text, Partial Link text, Tag name, and Xpath.

Click here to know the importance of JAVA in Selenium

Find Elements():

This command takes an object element and returns the list of parameters. And if there are no elements found, this returns an empty list. If the match found, it returns the elements collection. Moreover, like the array, all the elements are indexed with a number starting with zero.

So now let’s have a look at how selenium tutorial differentiates these elements:

Find Element Find Elements()
It returns the first most web element This returns the web elements list
If there are no elements matching the locator strategy, this throws an exception No such element Returns an empty list, if there are no web elements matching the web strategy.
It will find only one web elements It will find the collection elements
No index numbers It returns a web elements list starting with zero

Now we will see the various selenium web elements:

Text box :

These boxes accept the typed values and show  them as they are

But there are some text data, that requires to hide from the end users like passwords. In such cases, it would display the text in dotted format.

And you can add these elements in the project using the following code.

web element name = driver.findelement("name"));

web element password = driver.findelement("passwd"))";
How to send values into the Text boxes?

People can easily send values into the text boxes using sendkeys() method.


How do you delete your values in input boxes?

Clear method is used to delete the text in the input box. And it does not require any special parameter. Selenium automation testing says this snippet will clear out the text field  from the name and password fields

The complete working of the code is  shown below

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;


import org.openqa.selenium.*;

public class Form {

public static void main(String[] args) {

// declaration and instantiation of objects/variables


WebDriver driver = new ChromeDriver();

String baseUrl = "URL"; // given the URL to test


WebElement email = driver.findElement("email"));

WebElement password = driver.findElement("passwd"));



System.out.println("Text Field Set");

// Deleting values in the text box



System.out.println("Text Field Cleared");

// Find the submit button

WebElement login = driver.findElement("SubmitLogin"));

// Using click method to submit form



System.out.println("Login Done with Click");

//using submit method to submit the form. Submit used on password field





System.out.println("Login Done with Submit");





So after entering the data in the fields, the user needs to confirm the client, regarding the name and password confirmation. At this moment, buttons are required. For example, Sign in and Submit buttons

The buttons were usually classified into two types namely checkbox and Radio buttons

Check box :

The checkbox is used to select more than options in a group. With the click() method, we can toggle the checkbox on /off. The code provided below will click on Facebook “keep me logged in ”  check the box twice and the output the result as true when the toggled is on and returns false if the toggled is off.

public static void main(String[] args)
WebDriver driver = new FirefoxDriver();
String base URL = "";
WebElement chkFBPersist = driver.findElement("persist_box"));
for(int i=0;i<2;i++){;


isSelected() is used to check the toggled status( either on (or) off)

Also check the commands of Selenium Automation tool

Radio buttons():

And Radio is used to select only one option among multiple options.  Moreover,  like Text buttons, Radio buttons can be toggled using the click() method.

WebElement radio1 = driver.findElement("vfb-7-1"));
WebElement radio1 = driver.findElement("vfb-7-2"));;

radio2. click();

check out the it training  complete button code

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;


import org.openqa.selenium.*;

public class Form {

public static void main(String[] args) {

// declaration and instantiation of objects/variables


WebDriver driver = new ChromeDriver();

driver.get("URL");//Provide the URL to test

WebElement radio1 = driver.findElement("vfb-7-1"));

WebElement radio2 = driver.findElement("vfb-7-2"));

//Radio Button1 is selected;

System.out.println("Radio Button Option 1 Selected");

//Radio Button1 is de-selected and Radio Button2 is selected;

System.out.println("Radio Button Option 2 Selected");

// Selecting CheckBox

WebElement option1 = driver.findElement("vfb-6-0"));

// This will Toggle the Check box;

// Check whether the Check box is toggled on

if (option1.isSelected()) {

System.out.println("Checkbox is Toggled On");

} else {

System.out.println("Checkbox is Toggled Off");


//Selecting Checkbox and using isSelected Method


WebElement chkFBPersist = driver.findElement("persist_box"));

for (int i=0; i<2; i++) { ();

System.out.println("Facebook Persists Checkbox Status is -  "+chkFBPersist.isSelected());





And the next option in selenium tutorial for beginners  is Drop down the list:

Usually, a drop-down list is used to select one among many options. In other UI designer prefer drop-down list if the options were greater than the single webpage.  A drop down in HTML is done using the following code

<select id = "flowers" multiple = "">
<option value = "Rose">Rose</option>
<option value = "lilly">Lilly</option>
<option value = "Jasmine">Jasmine</option>
<option value = "lotus">lotus</option>

So to perform this option in Web driver, we need to execute the following code. Usually in selenium, we do import the package. 

public static void main(String[] args){
WebDriver driver = new Firefoxdriver();
Selecr fruits = new Select(driver.findElement("flowers")));

Moreover, this select has various commands,  

Method Description
SearchByVisibleText() and deselectByVisibleText() It selects/ deselects the options that displays the text matching parameter.
selectByValue() and deSelectByValue() It selects are deselects the option , whose value attribute matches the specific parameter
selectByIndex() and deSelectByIndex() This command selects / deselects the option at the given index
isMultiple() It returns true if the dropdown allows multiple selections at a time
deselectAll() This is element when the dropdown supports multiple selections. This usually clears all the entries.

And we can execute the dropdown in  web driver with the following code:

package newpackage;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;


import org.openqa.selenium.By;

public class accessDropDown {

 public static void main(String[] args) { 


    String baseURL = "URL";//Provide the URL to test

    WebDriver driver = new FirefoxDriver();


Select drpCountry = new Select(driver.findElement("country")));


//Selecting Items in a Multiple SELECT elements


Select fruits = new Select(driver.findElement("fruits")));




Image Links :

These are the links in the web pages represented in an image. when Clicked, this navigates to the different window (or) different page.  Since these are the image files, they cannot By.linkText() and By.partialLinkText() methods. So at this moment, we need to use By.cssSelector (or) By.Xpath

Mouse click and Keyboard Event:

Using Advanced API Interactions, we can handle keyboard and mouse events. To execute these events both Actions and Action classes are required.   This action class provides the following mouse and keyboard clicks.

Method Description
Click and Hold() At the mouse current location, it clicks without releasing
Context Click() At the current mouse location, it performs a Context Click
Double Click () It performs double click at the current mouse location
Drag and Drop ( Source, target) It performs Click and hold at the source element location and then  releases the mouse at the target location
Drag and drop (Source, x-offset, Y-offset) This method initially performs Click and hold at the source element location and moves by the given offset and then release the mouse at the target location
Keydown (modifier_key) This performs a modifier key press. It does not release the modifier key subsequent actions and assumes key presses
Key up This performs a key release
Release() At the current mouse location, it releases the left mouse button
moveToElement (to Element) It moves the mouse to the element middle
MoveByoffset(X-offset, Y-offset) It moves the mouse from its current position by the given offset
Send Keys (On Element, Character Sequence)` It sends a series of keystrokes onto the element

Likewise, there are some other web elements like images, hyperlinks, error messages, Combo box, Web table, and Frames.

Also, check how the connection happens between Selenium and Excel

to our newsletter

Drop Us A Query

Trending Courses
  • Microsoft Azure Architect Technologies(AZ-300) | ITGuru
    Microsoft Azure Architect Technologies(AZ-300)
  • Azure is a great Microsoft Cloud Computing platform in providing various cloud services through online. ITGuru Certified Azure Architect certification course gives you the practical knowledge on Azure Cloud platform through real-world use cases from live experts

  • ServiceNow Admin Training | ITGuru
    ServiceNow Admin Training
  • Getting knowledge of cloud platforms like ServiceNow is essential in today’s world for the smooth running of projects in cloud platform. Turn your dream to the reality of becoming the Certified ServiceNow Administrator through ServiceNow Administration online certification Course with practical examples by live industry experts through online at ITGuru with real-world use cases.

  • Workday Financials Training | ITGuru
    Workday Financials Training
  • knowing the basics on any platform like Workday is not enough to sustain the IT industry. Hence it is essential to go beyond on Workday basics like Workday Financials training which lets you know the application of Financials management in real -world use cases from ITGuru Live Experts in a practical way.

  • Workday Training
  • An organization is considered as the best one when it offers the best benefits to the employee. Moreover, the greater the employee benefits, the greater the contribution to the organization. ITGuru let you know the practical workday Human Resource Management(HRM) features with live examples by experts

  • Python Online Course | ITGuru
    Python Online Course
  • Turn your dream into reality by ITGuru live experts with real-world use cases through practical knowledge on python online course and become the certified associate in python programming and become a master in python programming

  • Python Programming | ITGuru
    Python Programming
  • Python is the trending programming language in the IT industry. Mastering in python programming gives you more value among the people in the IT industry. Hence start today to learn python programming online by live experts with real-time uses cases at ITGuru

100% Secure Payments. All major credit & debit cards accepted.

Call Now Button