The id global attribute defines an identifier (ID) which must be
unique in the whole document. Its purpose is to identify the element
when linking (using a fragment identifier), scripting, or styling
So as per standard, ID should be unique across the entire page ( Even though some advocate that HTML5 requires ID to be unique only in the same subtree ( in the same hierarchy) )
So, the question would be:
What happens if ID is not unique?
In old days, it would have given unintended behavior like you click one checkbox but a different checkbox gets selected and so on.
But now browser technologies have advanced a lot and they have removed the strict HTML validation. This means that browsers are smart enough to understand the exact element that a user action intended at.
For example, read the below article
Here the author expects the code for the checkbox to break but now the code works fine in all browsers.
So things could work even though you have duplicate IDs.
The main risk with this approach is that your code becomes more browser-dependent. So if the browser changes the way they render duplicate ID then things could break.
- If you are working in a high customer-facing complicated webpage
which gives great importance to Quality and coding standard, raise the bugs and get it fixed.
- If you are working in a noncritical system that doesn't care intermittent breakage in the web app, then still raise it and wait for them to mark it as no fix required ( Then point to them the bug when something breaks ).
- From an automation perspective, Find other ways to uniquely identify an element like chaining web elements together, or using other attributes.
- If nothing works demand for an id for at least those elements which you cannot uniquely identify.