Junior — Middle
What types of locators do you prefer for finding elements on a page?
sobes.tech AI
Answer from AI
To find elements on a page, I prefer to use the following types of locators:
- ID — the fastest and most reliable method if the element has a unique identifier.
- CSS selectors — flexible and allow finding elements by classes, attributes, nesting.
- XPath — useful for complex structures and finding elements by text or relative position.
For example, to find a button with the class "submit":
button.submit
If an ID is available, it's better to use it:
#submit-button
The choice of locator depends on the stability and uniqueness of attributes on the page to ensure tests are resilient to interface changes.