量角器的新手和收集选择选项的困难 [英] New to Protractor and difficulty with collecting Select options
问题描述
自学量角器和解决非 Angular Web 应用程序的问题,并从选择控件中获取所有值的列表.这是 html,但似乎无法验证列表.(本站第一个重量选择框)
self teaching protractor and fighting issues of non angular web app and getting the list of all values out of a select control. here is the html but can't seem to validate the list. (first weight select box at this site)
http://halls.md/body-surface-area/bsa.htm
还有我失败的语法.我的脚本引用元素和选项成功执行,但无法正确评估列表中选项值的捕获:
and my failed syntax. my script executes successfully referencing the element and option but can't correctly evaluate the capture of option values in the list:
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
表示法——至少看起来更干净.
First of all, use element
notation - would at least look cleaner.
如果你想在控制台看到选项文本或值,你需要解析promise:
If you want to see the option text or value on the console, you need to resolve promises:
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 结构:
Also, I recommend to abstract select->option HTML constructions with the help of this answer:
这篇关于量角器的新手和收集选择选项的困难的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!