When working with Watir and Watir-Webdriver there is a standard DOM property for an element such as name, class, id, index, scr, href etc,  which is usually a straight forward way to locate an element on the page you need to get a handle of, such as select lists. But in certain cases, we come across non-standard attributes in the DOM where the usual Watir /Webdriver syntax just doesn’t work . The reason for this seems to be when the ‘type’ attribute is set to ‘text’ in for the  drop-down. One way to get around this may be to use Xpath to gain control of the element.

Handling select list having non-standard attributes using Xpath

At 3Qi Labs, in one of our banking customers applications, we encountered a unique non-standard HTML structure being used in defining a <select> tag, which refers a select list (drop-down list).
The standard attributes of a <select> tag are class, id, index, name, text, value etc, but here  type = ‘text’  is used  which is very unusual for <select> tag.  As a result, accessing this type of select list is not straight forward .

Select lists in the application under test:

select list

Its DOM attributes:

In the above example, ‘class’ is general…..


Here’s the solution for non-standard select lists we came up with:


nor taking care of form, frame helped.
Xpath is used in cases where per-defined attribute doesn’t locate the element. Using Xpath we could access the ‘select list’ element.
It can set a value and also validate selected value for that particular select list element.

It can also interact with other attributes. This sets the option to value.

This validates the selected option value.