Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (19.7k points)

How can I filter elements which have the same class?



  <p class="content">Link1.</p>





  <p class="content">Link2.</p>



1 Answer

0 votes
by (62.9k points)

Class Name Locator:

Class Name locator when matches the values specified in the attribute name “class”,  retrieves the web-element.


findElement(By.className("Element Class"))

  1. Open Mozilla Firefox and navigate to the Facebook application.

  2. Open Firebug and inspect the Email input box. Take a note of its Class.

  3. Follow the below screenshot to do so.

Locate Element By Class Name Locator

Use the below:


<input id="email" class="inputtext" type="email" tabindex="1" value="" name="email">


Value to be added in the By.className method:



package seleniumTutorial;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

public class Locators {

public static void main (String [] args){

WebDriver driver = new FirefoxDriver();


driver.findElement(By.className("inputtext")).sendKeys("Software Testing Material");


If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium certification

Browse Categories