Selenium Locators:

In Selenium, locators are used to find and interact with elements on a webpage. They help automation scripts identify specific elements for actions like clicking, typing, or verifying content.

Here are the main types of locators:

Lets implement with an example

Step1: Launch this page which contains an simple user registration form - https://learnqatesting.com/seleniumlocatorsform

Step 2: Rightclick and select Inspect

Step 3: Mouse over on each field and identify the locators to interact and do validation

To enter the Name - we can use ID attribute as below

driver.findElement(By.id("nameInput"))

To enter the Email - we can use Name attribute as below

driver.findElement(By.name("useremail"))

To enter the Password - we can use class attribute as belo

driver.findElement(By.className("useremail"))