New to Protractor and difficulty with collecting S

2020-05-01 07:32发布

问题:

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