量角器新手,难以收集 Select 个选项

New to Protractor and difficulty with collecting Select options

自学量角器和解决非 angular 网络应用程序的问题,并从 select 控件中获取所有值的列表。这是 html 但似乎无法验证列表。 (本站首重select框)

http://halls.md/body-surface-area/bsa.htm

和我失败的语法。我的脚本引用元素和选项成功执行,但无法正确评估列表中选项值的捕获:

var tempstr = browser.driver.findElement(by.xpath('//select[@name="wu"]'));  //get all the options
  var tempstrs = tempstr.findElements(by.tagName('option'));
  console.log(tempstrs[1]);

首先,使用 element 符号 - 至少看起来更干净。

如果你想在控制台上看到选项文本或值,你需要解决承诺:

var weightUnitSelect = element(by.name("wu"));
var options = weightUnitSelect.all(by.tagName("option"));

options.first().getText().then(function (text) {
    console.log(text);
});

此外,我建议在这个答案的帮助下抽象 select->option HTML 结构: