-
Book Overview & Buying
-
Table Of Contents
Hands-On Automated Testing with Playwright
By :
While they might not be the most reliable for long-term use, CSS and XPath selectors can be very helpful when dealing with legacy code or third-party components. Sometimes, you just don’t have control over an element’s accessible attributes. If an element doesn’t have ARIA roles, labels, or other accessibility features, locators may not work as expected.
That’s where fallback selectors come in. They can get the job done when HTML is poorly structured or you’re working with external components. Just keep in mind that these selectors often depend on the page’s structure or internal implementation details, which means they can break more easily if the page changes. So, while fallback selectors are useful in certain situations, it’s best to stick with getBy* locators or test IDs (we’ll discuss test IDs in a bit) whenever you can.