Is it a good idea to use "data-" attributes to replace the "id" attributes in elements(tags) for css-selection purposes and then use those "data-*" attributes in automation testing scripts?
Is it a good idea to use "data-" attributes to replace the "id" attributes in elements(tags) for css-selection purposes and then use those "data-*" attributes in automation testing scripts?
No.
CSS selection and DOM-tree selection on id is much faster than selection any other attribute. Data-attribute select might be less efficient than selection on other attributes in somebrowsers.
The exception might be if you are abusing id attributes: storing something that is not just an identifier in them (e.g. composite data or something not unique). Selecting parts of id values, if supported, gives terrible performance. I would recommend using data attributes over abusing id attributes.
Factually, you can use any of the attributes of an element.
So, Yes, you can use data-* attribute instead of id attribute as well provided the element is uniquely identified.
data-* attributes are used to store custom data private to the page or application.data-* attributes gives us the ability to embed custom data attributes on all HTML elements.data-* attributes consist of two parts:
data-data- will be completely ignored by the user agent.