I'm new to test automation with Selenium (Python) and just wondering if it makes sense to locate elements on webpages via a custom attribute?
In some places the IDs of the elements are generated and have a new ID the next time the page is opened.
Names and classes can sometimes change and are not unique.
The developer offered me to add an additional attribute to the elements that I can use for the test automation.
<a href="..." name="my-link" data-test-id="my-unique-test-id">Link Text</a>
I found the idea quite charming because it is completely detached from developer purposes. This attribute is used explicitly for locating purposes in test automation.
Unfortunately, I have currently found only the way to address custom attributes via XPath. And that should be much slower than identifying elements by ID or name.
Can you please share your experiences with me?
Is there any library in Python that I can use to find such a custom attribute more efficiently?
Have you found a better way to locate elements?