Locators
Locators ~30 mins

Locators are 8 types: (10min)

Locators Find different elements on web page
id To find the element by using id attribute of the element
name To find the element by using name attribute of the element
className To find the element by using Class attribute of the element
linkText To find the element by text of the WebElement having
partialLinkText To find the element with link text with partial match
tagName To locate the element using tag name of the target element
xpath To find the dynamic element and traverse between various elements of the web Page
cssSelector CSS path also locates elements having no name, class or ID

How to use Locators?

Basic Locators
-- id → can be identified as id attribute of an element
-- name →can be identified with name attribute
-- className → can be identified as class attribute
-- linkText → can be identified with text with

xpath
Xml path -> uniquely identify or address parts of an XML document
-> to navigate through a page's HTML structure and locate
the element

Syntax: driver.findElement(By.locator(“value"));

When to/ not to use?

Locators When do you use? When you cannot use?
id Always(Most preferred) Numbers
name If “id” does not exist Duplicate
className When classis unique without white spaces White spaces, Duplicate
linkText If it is a link Duplicate
tagNname For collection of objects Duplicate
Xpath If none of the above, works Xpath can change
cssSelector Thisisthe last option you have! CSS can change