New to Protractor and difficulty with collecting Select options

旧街凉风 提交于 2019-12-20 05:40:52

问题


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]);

回答1:


First of all, use element notation - would at least look cleaner.

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);
});

Also, I recommend to abstract select->option HTML constructions with the help of this answer:

  • Select -> option abstraction


来源:https://stackoverflow.com/questions/29321521/new-to-protractor-and-difficulty-with-collecting-select-options

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!