How do I find an element by its attribute?

How do I locate an element based on its attribute?

To get an element by attribute, use the querySelector() method with a selector that targets the relevant attribute.