Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Selecting an option from a dropdown #75

Closed
MrTricks opened this issue Sep 6, 2013 · 8 comments
Closed

Selecting an option from a dropdown #75

MrTricks opened this issue Sep 6, 2013 · 8 comments

Comments

@MrTricks
Copy link

MrTricks commented Sep 6, 2013

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

All USA UK INDIA AUSTRALIA

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?

@juliemr
Copy link
Member

juliemr commented Sep 6, 2013

Parentheses are slightly off! Should be:

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

@juliemr juliemr closed this as completed Sep 12, 2013
@joshrtay
Copy link

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?

@derekhe
Copy link

derekhe commented Feb 17, 2014

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

@glepretre
Copy link

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

@r0ckyyr0cks
Copy link

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

Aerial Hybrid Roads Standard

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?

@sallojusuresh
Copy link

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

@Zehra-89
Copy link

Zehra-89 commented Sep 5, 2015

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

@ghost
Copy link

ghost commented Aug 29, 2016

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

8 participants