Ian Richards Ian Richards - 4 months ago 13
AngularJS Question

How to get option value of select element

I am trying to get the option value of a select element using Protractor. However, I'm not able to find the option element.

HTML

<select ng-options="opions.c as options.n for option in options" ng-model="model">
<option value="0">Option 1</option>
<option value="1">Option 2</option>
</select>


Spec-file

describe('testing select option', function() {
it('', function() {
ptor = protractor.getInstance();

//This will not get the option required
ptor.findElement(protractor.By.binding('model'));
});
});


I cannot seem to find a way to grab the option value as I haven't found a function that I can use that doesn't give and exception or error message.

Does anyone know how to resolve this issue?

Answer

ok again I have now been able to figure out how to grab the option element with protractor.

the example code below shows how to accomplish this.

ptor.findElement(protractor.By.css('select option:nth-child(value of the option you require IE: the number)')).click();