angularjs - 在 Protractor 中,为什么具有 value 属性的列表项元素上的 WebElement.getAttribute ('value' ) 始终返回 0?

标签 angularjs selenium protractor

我有一个包含以下元素的指令

<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> 的值标签必须是数字。

来自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 ().

关于angularjs - 在 Protractor 中,为什么具有 value 属性的列表项元素上的 WebElement.getAttribute ('value' ) 始终返回 0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29738373/

相关文章:

javascript - 访问 extjs 动态创建的元素

javascript - 谁能帮我解释使用 selenium webdriver 进行图像验证的 javascript 代码?

python - 在 Selenium 中访问浏览器日志?

internet-explorer - Protractor:驱动程序可执行文件的路径必须由 webdriver.ie.driver 设置

angularjs - 为什么 Angular ng-options 值包含值数据类型?

c# - 如何读取 MVC Controller 方法中的 web.config 设置并在 angularjs View 、 Controller 和服务中访问它们?

angularjs - 保存新属性会覆盖 firebase 对象

angularjs - 使用 Phantom.js 使用 Protractor 进行 e2e 测试

Angular 迁移(从 4 到 6)e2e --proxy-config 不工作

javascript - Angular : Dealing with reload page and User Authentication