UrbanPro
true

Learn Personal Trainer from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Understanding Locators in Selenium

Pradeep Shankar Chate
08 Sep 0 0

Why Locators are Important?

When we automate a web application, Selenium needs a way to find elements (like textboxes, buttons, links) on a web page.
Locators help us identify these elements so that we can perform actions such as click, type, select, or verify text.


---

Types of Locators in Selenium

1. ID

Every element can have a unique ID.

Example:

driver.findElement(By.id("username")).sendKeys("Lata");

 

2. Name

Uses the name attribute of the element.

Example:

driver.findElement(By.name("password")).sendKeys("mypassword");

 

3. Class Name

Finds element using the CSS class value.

Example:

driver.findElement(By.className("login-btn")).click();

 

4. Link Text

Finds links by their exact text.

Example:

driver.findElement(By.linkText("Forgot Password?")).click();

 

5. Partial Link Text

Finds links by partial matching of text.

Example:

driver.findElement(By.partialLinkText("Forgot")).click();

 

6. XPath

A powerful way to locate elements using XML path.

Example:

driver.findElement(By.xpath("//input[@id='username']")).sendKeys("test");

 

7. CSS Selector

Fast and widely used.

Example:

driver.findElement(By.cssSelector("input#username")).sendKeys("admin");

0 Dislike
Follow 1

Please Enter a comment

Submit

Other Lessons for You

Top 20 selenium interview questions and answers
2. Difference between Selenium 2 (WebDriver) and Selenium 3/4.👉 Selenium 2 introduced WebDriver.👉 Selenium 3/4 improved architecture, added W3C compliance, relative locators, Chrome DevTools integration. ...

Top 20 Selenium Interview Questions with Hands-on Practice
Selenium WebDriver – automation with multiple browsers Selenium Grid – run tests in parallel/distributed 2. Difference between Selenium 2 (WebDriver) and Selenium...

Top 20 Selenium Interview Questions with Hands-on Practice
Selenium IDE – record & playback Selenium WebDriver – automation with multiple browsers Selenium Grid – run tests in parallel/distributed 2. Difference between...

Writing Your First Cucumber Test Scenario in Plain English
Description:Cucumber allows us to write test cases in plain English using Gherkin syntax. Example: Feature: Login functionality Scenario: Successful login with valid credentials Given User is on the...

Top 20 selenium interview questions and answers
Selenium IDE – record & playback Selenium WebDriver – automation with multiple browsers Selenium Grid – run tests in parallel/distributed 2. Difference...

Looking for Personal Trainer ?

Learn from Best Tutors on UrbanPro.

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Personal Trainer Classes?

The best tutors for Personal Trainer Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Personal Trainer with the Best Tutors

The best Tutors for Personal Trainer Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more