Beware Of Using value Attribute On list element
In AngularJs development, we use custom attribute in our directive is nontrivial things. you can even use some attributes which may already be defined in W3C standards of that element. well, this doesn’t matter at most circumstance. But it is not recommended to override the meaning of those attribute originally defined by W3C. I have paid for this.
I have a directive nya-bootstrap-select which using a value
attribute on list element. I give this attribute
a new meaning that its value will be the option value for predefined options. It works well in AngularJS apps until I tried to add some e2e test on
it using Protractor.
In Protractor elements are selected by the webdriver api and I hasn’t look into the implementation of selenium, but I can sure it may take the W3C standard
and make its own implementation to retrieve the value of value
attribute.
As the W3C standards says:
This integer attributes indicates the current ordinal value of the item in the list as defined by the
<ol>
element. The only allowed value for this attribute is a number, even if the list is displayed with Roman numerals or letters. List items that follow this one continue numbering from the value set. The value attribute has no meaning for unordered lists (<ul>
) or for menus (<menu>
).
The list element has a value
attribute which only accepts integer value. Although I can use a String value in my AngularJS app but this is not warranted
by standard and can varies between implementations. Just as the selenium implementation, the WebElement.getAttribute(‘value’) on my directive always
return 0
. This is not my expected.
In conclusion, It is recommended for those who want to use some predefined attribute on their own directive to look up the standard whether its behavior has already been defined to avoid conflicts and variants between implementations.