0

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]);
pnuts
  • 58,317
  • 11
  • 87
  • 139
ColtsFan
  • 13
  • 4

1 Answers1

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:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • yes, this has helped as I am just learning "locating" options...I was interpreting (name) as an attribute of the Select element and trying to identify with xpath...didn't work. browser.driver.findElement(by.xpath('//select[@name="wu"]')); rather than just locate the element via (name). – ColtsFan Mar 29 '15 at 18:07