Protractor: Selecting an option from a dropdown

Created on 6 Sep 2013  路  8Comments  路  Source: angular/protractor

Hi all. Hoping someone can help.

I have:

select ng-model="data.productType" ng-options="p for p in data.productTypes" class="ng-valid ng-dirty">




I am trying to select one of these values using Protractor. I have tried a few methods including:

ptor.findElement(protractor.By.css('select option:2').click());

But I get:

TypeError: Object By.cssSelector("select option:2") has no method 'click'

Any idea what is wrong?

question

Most helpful comment

i'm having difficulty selecting an option from a select as well. i tried:

element(by.css('select option[value="1"]')).click()

and although it selects option 1 the dropdown does not go away. any thoughts?

All 8 comments

Parentheses are slightly off! Should be:

ptor.findElement(protractor.By.css('select option:2')).click();

i'm having difficulty selecting an option from a select as well. i tried:

element(by.css('select option[value="1"]')).click()

and although it selects option 1 the dropdown does not go away. any thoughts?

Same issue when select option and the dropdown is still there.

@joshrtay @derekhe If you're testing with Firefox, this may be related to #480

On the similar ground, I am not able to select Hybrid. I have:

What I am trying is:

element(by.model("selectedBaseLayer")).click();
var bLayer = element.all(by.model("selectedBaseLayer"));
expect(bLayer.count()).toEqual(1); // it fails to give me the count if I change it to 4
element(by.css('select option[value="1"]')).click();

And it does not click as it says, "ElementNotVisibleError: element not visible". Can anyone point out my mistake please?

Hi,
If you would like to select 'Hybrid' value from a drop down, you need to arrange your code using call back sequence, as its a Asynchronous execution

A. Selecting from drop down value:
//First click on Drop:
element(dropdownlocator).click().then(function(){
//second move mouse to particular value in list
browser.action().mouseMove(element(by.xpath(".//*[text()='Hybrid']"))).click().perform();
});

B. Verifying using count:
element.all(by.model("selectedBaseLayer")),count().then(function(n){
expect(n).toEqual(1); });

hi,
I am trying to select value from calendar control using protractor, any one can please help

Thanks @sallojusuresh just careful that browser.action().mouseMove(element(by.xpath(".//*[text()='Hybrid']"))).click().perform();
});

needs to be browser.actions().mouseMove... having the browser.action() is not a function had me stumped for a bit thanks again

Was this page helpful?
0 / 5 - 0 ratings