我有一个包含以下元素的指令
<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>
如代码块所示,每个 <li>
元素有 value
属性。
但是当我使用 Protractor 获取它们的值时,它总是返回 0
.
像这样:
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'
如何获取 <li>
的实际值使用 Protractor 的元素?
最佳答案
<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 ().
关于angularjs - 在 Protractor 中,为什么具有 value 属性的列表项元素上的 WebElement.getAttribute ('value' ) 始终返回 0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29738373/