protractor icon indicating copy to clipboard operation
protractor copied to clipboard

Selecting an option from a dropdown

Open MrTricks opened this issue 13 years ago • 8 comments

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?

MrTricks avatar Sep 06 '13 14:09 MrTricks

Parentheses are slightly off! Should be:

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

juliemr avatar Sep 06 '13 17:09 juliemr

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?

joshrtay avatar Jan 23 '14 01:01 joshrtay

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

derekhe avatar Feb 17 '14 06:02 derekhe

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

glepretre avatar Mar 07 '14 13:03 glepretre

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?

r0ckyyr0cks avatar Feb 06 '15 08:02 r0ckyyr0cks

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); });

sallojusuresh avatar Feb 06 '15 10:02 sallojusuresh

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

Zehra-89 avatar Sep 05 '15 11:09 Zehra-89

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

ghost avatar Aug 29 '16 08:08 ghost