Selectors are strings that represents a specific DOM element on the page. When writing browser-level tests, it’s recommended to use selectors that are robust to avoid test flakiness when the DOM structure changes.
Currently, the browser module supports the standard CSS and XPath selectors.
Note: Text-based selectors are currently not supported. This will be supported in future releases.
The selectors that you choose should not be tightly coupled to any behaviour or styling changes. If your application is prone to changes frequently, it’s recommended to use user-facing attributes or custom data attributes as these are not tightly coupled to the element.
|✅ ||User-facing attributes such as ARIA labels are rarely changed so these are great candidates.|
|✅ ||Custom data attributes are not tightly coupled to the element.|
|✅ ||Text selectors are also great as text content rarely changes. While we don’t support text-based selectors as of yet, xpath can be used as a workaround.|
|⚠️ ||Selecting an element via its ID is also recommended if the ID doesn’t change.|
|⚠️ ||Selecting an element via its class name should be kept to a minimum as class names can be duplicated.|
|❌ ||Generic elements are not recommended because this has no context.|
|❌ ||Absolute paths are not recommended as these are tightly coupled to the DOM structure.|