1

Since a webpage should only have unique id attributes, does that mean you should report that as a bug on an otherwise functional page?

For one, it surely makes automation more difficult, but for some that might not be a sufficient reason to change the id-s.

1
  • What is the software under test? is it shopping site ? a managemnet tool web interface etc ?
    – PDHide
    Feb 20 '20 at 10:11
4

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 (with CSS).

https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id

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

https://www.deque.com/blog/unique-id-attributes-matter/

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.

Summary

  1. 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.
  2. 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 ).
  3. From an automation perspective, Find other ways to uniquely identify an element like chaining web elements together, or using other attributes.
  4. If nothing works demand for an id for at least those elements which you cannot uniquely identify.
2

This would mostly be up to the team or requirements for this website. Some use unique id,'s, some don't, some don't even use id's for all webelements.

Since this does indeed make automation harder, you could have a meeting with the devs or team in general to discuss this and work out how important this is in the overall scope of the project.

2
  • When this occurred in my ex-company I just had a chat with the developer sitting in the next room and he changed the ids. But now I'm the new guy in a bigger company and with remote developers so I'm not sure how will they react.
    – Mate Mrše
    Feb 20 '20 at 8:45
  • Ideally that should still be acceptable for you to do (either in person or through your chat tool), since you are the automation guy here feedback like this might even be expected from you. However any change or rework for this may require a large amount of time, which could interfere with any planning already in place. So having a discussion with the developer(s) can indeed be the way to go but might require follow-up with you manager/lead/... depending on the outcome.
    – Blub
    Feb 20 '20 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.