Identifying Web Elements using Selenium Webdriver - Blogs

Identifying Web Elements using Selenium Webdriver

What is Web Element?

                Anything present on the webpage is Web Element. Such as text box, button, link etc. Before performing any action in Selenium we should identify the Web Element using its characteristics given by the application developer with the help of HTML.

What are the components of Web Element?

While developing the Web Element using HTML, developer will specify following components.

  1. HTML Tag: Any word which is present after the ‘<’ symbol can be a HTML tag.


  1. Attributes: Any word present after the HTML till the ‘>’ symbol is called as Attributes. Which contain ‘=’ symbol. Left side of the ‘=’ symbol is called as ‘Property Name’. Right side of the ‘=’ symbol is called ‘Property Value’.

Example: Type=”text”, Value=”true”, Multiple= “true”, etc

  1. Text: Any word which is present after the ‘>’ symbol till the end of the respective HTML tag is called as Text.








For the above code:

  1. Text of the title is “Canarys Automation Pvt Ltd”
  2. Text of the input is not present
  3. Text of the body is “company”
  4. Text of the html is “Canarys Automation Pvt Ltd” and “company”

What are the Locators?

                Locators are the html tag, attribute, text and expressions. Which are used to identify the Web Element. Locating an Web Element is essential part in Selenium WebDriver because when you wants to take some action on element, first you need to locate that specific element to perform action. In selenium there are 8 types of Locators.


Frequently used locator to locate the UI element using a unique ID. If unique ID value is not available, they will use CSS selector locator followed by XPath locator.

How to Locate/Select single/ multiple check box, single/multiple option in dropdown list, Links, Text Box and Button using Selenium Web driver?

1. Locating the Text Box and enter search text: Inspect the text box on which you wants to perform action. After inspecting you will get the below screen.


Code to Locate the Text Box and enter text:

driver.findElement ( ("SearchByKey")).sendKeys ("enter search text");

2. Locating Button and click on it: Inspect the button which you wants to click.


Code to Locate the Button and click on it:

driver.findElement (( ("btnSearch"))).click ();

3. Selecting single/multiple check Box: Right click on check box/s and inspect. Below screen will appear.


Code to select single checkbox:

driver.findElement(By.xpath ("//input[@value='false']")).click();

Code to select Multiple checkbox:

String Xp="//input[@value='false']";

Listallchkbx=driver.findElements (By.xpath (Xp));

int count=allchkbx.size();

for(int i=0; i


WebElement checkbox=allchkbx.get(i);;


4. Selecting single/multiple list box: In order to select required option in the list box we should use selectBy()  of select class. In order to do this we should perform following steps.

  • Find the Web Element
  • Create the object of the selected class
  • Select the required option using anyone of the following method.
    1. SelectByVisibleText(“String Text”)
    2. SelectByIndex(int)
    3. SelectByValue(String Value)


Code to select single list box:

String WE = "html/body/div[2]/div[1]/div/div/div/form/div[1]/div/div/button"

WebElement listBox = driver.findElement (By.xpath (WE)).click ();

Select select1 = new Select (listBox);

select1.selectByVisibleText ("offers");

Code to select multiple list box:

String WE = "html/body/div[2]/div[1]/div/div/div/form/div[1]/div/div/button"

WebElement listBox = driver.findElement (By.xpath (WE)).click ();

Select select1 = new Select(listBox);


select1.selectByVisibleText ("products");

select1.selectByVisibleText ("services");

select1.selectByVisibleText ("ratings");

5. Counting the number of links present on web page: Code to count the number of links present on webpage.

List allLink=driver.findElements(By.xpath("//a"));

int count= allLink.size();




What is Defect? Defect Life Cycle in Software Testing.

Defect is an unexpected behavior of the software application flow against the requirement specificat...

Read More >

What are Frames? How to handle frames in Selenium WebDriver with C#?

IFrame (FullForm: Inline Frame) is an HTML document that is included in another HTML document and is...

Read More >

What is Synchronization? Handling Synchronization in Selenium WebDriver using C#:

Synchronization meaning: when two or more components involved to perform any action, we expect these...

Read More >

Sending Test reports by Email using Office 365, Gmail

Wouldn’t it be great if Test Report are sent automatically across team as soon the Test Execut...

Read More >

Extent Reports in Selenium CSharp (C#)

Reports play a fundamental role when it comes to TESTING. Tester can now  know the real-time r...

Read More >

How to Set Up Selenium WebDriver in Visual Studio Enterprise 2015?

Pre-requisite : Visual Studio Enterprise 2015 application should be installed into the system.Create...

Read More >

Assertions in Coded UI

Let us discuss how to add assertions in coded UI. Assertions are checkpoints/benchmarks to UI c...

Read More >

Analysis of Load Test Results

Analysis of Performance DataAfter you capture and consolidate your results, analyze the captured dat...

Read More >

Parallel Execution using Selenium Webdriver and TestNG

While testing a web application it is very important to test the application on different browsers. ...

Read More >


Try DevOpSmartBoard Ultimate complete Azure DevOps End-to end reporting tool

Sign Up

  • Recent
  • Popular
  • Tag
Monthly Archive

Contact Us
  • *
  • *