There are ways to get id attributes on elements working even just for test, but that will not work efficiently for testing purposes.
As id's need to be unique within the html, you have manage this for instance with a counter. If you do not keep them unique you'll be in a world of html behavior fun.
When you write your tests on a specific Id, the moment you add a widget somewhere in the user click path going up to the panel you want for test, your id will be higher then expected for the test. So it will fail and you'll need to fix ids. Very maintenance intensive.
Best to set an attribute on your element named 'data-xxxxxxx' (xxx as whatever you like) with a functional value. For instance if it's a value in a table, set the corresponding DB id, name or anything that identifies that row and is reusable.
data-xxxxx is also ignored by screen readers and the like - so no need to remove them from prod html. And there is no need to keep them unique in all your html - so you can't break behavior.
It's quite easy to do, and it'll work wonders for your setup & maintenance of playwright or selenium testing.
Op dinsdag 6 februari 2024 om 12:59:45 UTC+1 schreef Sebastian Bota: