Locating Web Elements by attribute/wildcard matching

0 votes

Sometimes we don’t have full control over the key/value pairs used in the HTML. For example, if you have to test a COTS (Commercial Of The Shelf) application or if you are tight to framework specific things, such as JSF or ASP.NET. In this case ids, or parts, are generated and tend to be long and brittle as they might contain generated numbers. A few examples:


<input id="ctl00_ContentPlaceHolder1_CustomUserControl1_Username" type="text" />

If you change the ClientIDMode property of the control to Static then you will see an id with the following value Username


<input id="j_id819:inputSequencenumber" type="text" />

In these circumstances you might want to use wildcards, so you will end up with less brittle locators.
Wildcards explained

Equals E[a=v] //E[@a=v]
Contains E[a*=v] //E[contains(@a, ‘v’)]
Starts-with E[aˆ=v] //E[starts-with(@a, ‘v’)]
Ends-with E[a$=v] //E[ends-with(@a, ‘v’)]

You can define the following locators for the mentioned HTML elements:





Examine your knowledge and play the ‘locator game‘.

Please follow and like us:
Locating Web Elements by text matching
Locating Web Elements by name