开发者

Selenium HTML attribute name to assist identifying content

开发者 https://www.devze.com 2023-03-21 06:50 出处:网络
I need to verify using Selenium (or similar framework) that certain HTML content/items are on the page using known unique identifiers.

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 att开发者_C百科ribute 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>


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

0

精彩评论

暂无评论...
验证码 换一张
取 消