What are Locators?
A locator is a command tells Selenium IDE which GUI elements it needs to operate on. Identification of correct GUI elements is a prerequisite to creating an automation script. The identification of GUI elements is more difficult sounds. Sometimes, you end up working with incorrect GUI elements or no elements at all. Hence, Selenium provides many Locators for locating a GUI element
Types of Locators in Selenium IDE
- Link Text
- DOM (Document Object Model)
Locating by IDThis is the most common way of locating elements. the ID's supposed to be unique for each element. Target Format: id=id of the element
Locating by NameLocating elements by name is very locating by ID. that we use the "name=" prefix instead. Target Format: name=name of the element
Locating by Name using FiltersFilters use when many elements have the same name. Filters are extra attributes used to distinguish elements with the same name. Target Format: name=name_of_the_element filter=value_of_filter
Locating by Link TextThis type of locator apply to hyperlink texts. We access the link by prefixing our target with "link=". then followed by the hyperlink text. Target Format: link=link_text .
Locating by CSS SelectorCSS Selectors are string patterns used to identify an element. it based on a combination of HTML tag, id, class, and attributes. It is more complicated than the previous methods. but it is the most common locating strategy of advanced Selenium users. it can access elements have no ID or name. CSS Selectors have many formats, but we focus on the most common ones.
- Id & Tag
- Tag and class
- Attribute and Tag
- Tag, class, and attribute
- Inner text when using this strategy, we always prefix the Target box with "css=".
Locating by CSS Selector - Tag & IDInner texts are the actual string patterns that the HTML label shows on the page.
Locate CSS Selector - Tag and ClassLocating by CSS Selector using an HTML tag and a class name is like using a tag and ID, but in this case, a dot (.) is used instead of a hash sign.
CSS Selector - inner textHTML labels are seldom given id, name, or class attributes. Inner texts are the actual string patterns HTML label shows on the page.
Locating by DOMThe Document Object Model in simple terms is the way by which HTML elements structured. Selenium IDE is using the DOM access page elements. If we use this method, our Target box will always start with "dom=document...". but, the "dom=" prefix removed because Selenium IDE is able to interpret anything. that starts with the keyword "document" to be a path within the DOM anyway. There are four basic ways element through DOM
Locating by XPathXPath is the language used when locating XML (Extensible Markup Language) nodes. Since HTML can be thought of as an implementation of XML, we can also use XPath in locating HTML elements.
- It can access almost any element, even those without class, name, or id attributes.
- It is the most complicated method of identifying elements because of too many different rules and considerations.