Ian Richards Ian Richards -5 years ago 114
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.


<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>


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

//This will not get the option required

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 Source

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();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download