Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium HTML attribute name to assist identifying content

I need to verify using Selenium (or similar framework) that certain HTML content/items are on the page using known unique identifiers.

I have control over the generation of the HTML, so I will mark the HTML tags with an attribute, but sometimes the usual candidates of id, name etc aren't available for me to use.

Is there an industry standard for such an attribute?
If not, anyone have any good suggestions?

The attribute shouldn't collide with any known attributes of any HTML elements or affect the web experience/behaviour (I don't care if someone reads the HTML source and sees it).

Some ideas I have are:

  • trace
  • debug
  • uid

Here's how I would like to use it for the example identifier "123456789":

<a trace="123456789" href="http://www.someurl.com">Click me!</a>
<span debug="123456789">Hello world</span>
<strong uid="123456789">Wow</strong>
like image 425
Bohemian Avatar asked Dec 12 '25 10:12

Bohemian


1 Answers

Use a HTML5 data-* attribute.

Custom data attributes are intended to store custom data private to the page or application, for which there are no more appropriate attributes or elements.

More information here: http://developers.whatwg.org/elements.html#embedding-custom-non-visible-data-with-the-data-*-attributes

They won't cause any problems in older browsers: http://caniuse.com/dataset

like image 61
thirtydot Avatar answered Dec 13 '25 22:12

thirtydot