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
1 day ago 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

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...

Introduction to Selenium WebDriver with Java
Selenium WebDriver is a powerful tool for automating web applications. It allows interaction with browsers using Java. Example Code: WebDriver driver = new ChromeDriver();driver.get("https://www.google.com");driver.quit(); Topics...

Interview Questions And Answer
Q1: What is Automation Testing? Answer: Automation Testing is the process of using tools and scripts to test software applications automatically. Instead of running test cases manually, scripts are executed...

Learn Automation Testing using Java
Are you still stuck in Manual Testing? It’s time to upgrade your skills and grab high-paying jobs in the IT industry! What You’ll Learn: Selenium WebDriver with Java TestNG & Cucumber...

Selenium Interview Practice Questions With Hands-On Examples
Description: Selenium is widely used for web automation. Practicing interview questions can help improve both concepts and practical skills. Q1: What are the different types of locators in Selenium? A1:...

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