Locator Approaches - Instructions
There are many ways to locate elements on a page. Each li has elements which can be found in different ways, and built around the locators offered by tooling.
Use Dev Tools To Inspect The Page
Use the inbuilt browser developer tools to inspect the DOM.
You’ll see that the li items have attributes or elements with attributes that can be used for locating them.
Try and find these using a variety of locators.
Exercises for Automating
Locate each of the items below and automate an assertion against the element.
tagName li- find theliitem using the element’s tag i.e.liid li- find theliwith the idfind-by-idclassName li- find theliwith classfind-by-class-namename button- find thebuttonwith the namefind-by-namepartial link text link- find theawith textpartial link text linkby using a partial match on the link textfull link text link- find theawith textfull link text linkby using a full match on the link textby css li- find theliitem with classby-cssusing a CSS selectorby xpath li- find theliwith a child span which has an idchild-of-liusing an XPath selectorimagebutton - find the image with the alt tagan image of a buttontestid li- find theliwith a test id attributedata-testidlabeled wrapped input value- find the input field with the labellabel wrapped(the input field is a child of the label)label for labeled input- the label elementlabel foris ‘for’ the input element (the input is a peer of the label, theformatches theid)find by placeholder- find the input field with the placeholderinputplaceholdertitled li- find theliwith titleli with titlepresentation role li- find theliwith the Aria rolepresentation