Bob Yuan
Bob Yuan

Reputation: 588

In Protractor, why does WebElement.getAttribute('value') on a list-item-element with a value attribute always return 0?

I have a directive which contains the following elements

<ol id="singleSelection" class="nya-bs-select" ng-model="model">
  <li class="nya-bs-option" value="a">
    <a>Alpha</a>
  </li>
  <li class="nya-bs-option" value="b">
    <a>Bravo</a>
  </li>
  <li class="nya-bs-option" value="c">
    <a>Charlie</a>
  </li>
</ol>

As the code block indicates, every <li> element has a value attribute. but when I use Protractor to get their value, it always returns 0.

Like this:

var selectOptions = element.all(by.css('#singleSelection .nya-bs-option'));
var value = selectOptions.get(1).getAttribute('value');

expect(value).toEqual('b'); // this will fail because expect 0 to equal 'b'

How can I get the actual value of a <li> element using Protractor?

Upvotes: 2

Views: 1307

Answers (1)

Aaron
Aaron

Reputation: 2475

The value of an <li> tag must be a number.

From the MDN docs on <li>

This integer attributes indicates the current ordinal value of the item in the list as defined by the 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 () or for menus ().

Upvotes: 2

Related Questions