Locator is a command that tells Selenium IDE which GUI elements (say Text Box, Buttons, Check Boxes etc) it needs to operate on. Identification of correct GUI elements is a prerequisite to creating an automation script.
There are various types of locators, using which we can identify a web element uniquely on the Webpage. The following figure shows a good depiction of several types of locators that Selenium supports.
Here are the locators included in Selenium: -
Id: This is the most common way of locating elements since
ID's are supposed to be unique for each element. It is similar to a class, we can
also identify elements by using the ‘id’ attribute. Target Format: id=id of the
element.
Name: Name attribute can also identify an element. Locating
elements by name are very similar to locating by ID, except that we use the
"name=" prefix instead. Target Format: name=name of the element.
Link: Text used in hyperlinks can also locate elements. In
other words, this type of locator applies only to hyperlink texts. We access
the link by prefixing our target with "link=" and then followed by
the hyperlink text. Target Format: link=link_text
DOM: The Document Object Model (DOM), in simple terms, is
the way by which HTML elements are structured. Selenium IDE is able to use the
DOM in accessing page elements. If we use this method, our Target box will
always start with "dom=document..."; however, the "dom=" the prefix is normally removed because Selenium IDE is able to automatically interpret
anything that starts with the keyword "document" to be a path within
the DOM anyway.
XPath: Xpath is the language used to query the XML document.
The same can uniquely identify the web element on any page. Since HTML can be
thought of as an implementation of XML, we can also use XPath in locating HTML
elements.
CSS: CSS is used to create style rules for webpages and can be used to identify any web element. CSS Selectors are string patterns used to identify an element based on a combination of HTML tag, id, class, and attributes. Locating by CSS Selector is more complicated than the previous methods, but it is the most common locating strategy of advanced Selenium users because it can access even those elements that have no ID or name.
If you are looking for hands-on training with projects then I would
recommend you to enrol in Technogeeks Selenium Automation Testing
program under a working IT professional.
No comments:
Post a Comment