With the help of Element Locators, we can locate element uniquely on the page. CSS and Xpath are most command and most usable element locators used in different automation tools like Selenium, Appium, Katalon Studio, Watir and many more.
In this course, we are going to cover
- Basic to advance understanding of CSS locatos
- Xpath Locators using Attributes
- Xpath Locators using Inner text
- Xpath Locators using Axis techniques
- Best practices while writing element locators
Here in this course, we are going to cover CSS and Xpath
CSS Class
The CSS Class locator finds the first element with a specific CSS class attribute. This is useful for locating items that have a unique style on the page. A common example is submit and login/logout buttons – because there is frequently only one control on the page with that style.
XPath
XPath is a language for traversing the structure of the DOM (document object model) of the web page. XPath locators are very powerful and flexible. Any element on the page can be located via one or more XPaths and most other locators can be expressed as an XPath. Excepting CSS Selectors, no other locators share this feature. A well-written XPath can be very robust, but a poor XPath can be fragile – meaning that it may break when the application changes.
A complete description of XPath is out of scope for this document and there is a plethora of great information available on the web regarding how to use it.
XPath locators are very powerful and flexible. Any element on the page can be located via one or more XPaths and most other locators can be expressed as an XPath. Excepting CSS Selectors, no other locators share this feature. A well-written XPath can be very robust, but a poor XPath can be fragile – meaning that it may break when the application changes.