question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proper Way of Selecting an Option from a Dropdown List

See original GitHub issue

Hi. What’s the current best way of doing this in protractor tests:

select('orderProp').option('Alphabetical')

for

<select ng-model="orderProp">
   <option value="name">Alphabetical</option>
   <option value="age">Newest</option>
 </select>

This was taken from the tutorial on http://docs.angularjs.org/tutorial/step_04 (last test at the end of the page). I am trying to convert e2e tests to protractor as an exercise and can’t figure out a clean way to select an option from a drop down list. Some examples found on the web seemed too verbose and, perhaps, outdated. Thank you.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

17reactions
khepincommented, Mar 11, 2014

I usually do something like:

var select = element.one(by.model('orderProp'));
select.$('[value="age"]').click();
10reactions
demisxcommented, Mar 11, 2014

Worked great! Thank you so much.

Just a recap for others. Until protractor implements a more natural way of selecting an option from a dropdown list, use @khepin method below. This is the cleanest one I’ve found so far.

Given this dropdown:

<select ng-model="orderProp">
   <option value="name">Alphabetical</option>
   <option value="age">Newest</option>
 </select>

And I want to select “Newest” option in my spec, do this:

// JavaScript
element(by.model('orderProp')).$('[value="age"]').click();

// CoffeeScript
element(By.model('orderProp')).$('[value="name"]').click()
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Select Value from DropDown using Selenium ...
Following is a step by step process on how to select value from dropdown in Selenium.
Read more >
What are the different ways to select an option from a ...
Your answer · selectByValue(): You can select an option by using Value attribute provided for each option in dropdown menu. · selectByIndex(): ...
Read more >
What are the different ways to select an option from ...
We have different ways to select an option from a dropdown using Selenium webdriver. This is done with the help of the Select...
Read more >
HTML Select Tag – How to Make a Dropdown Menu or ...
The select tag normally goes within a form element, ... This attribute lets the user select multiple options from the dropdown menu.
Read more >
Video: Create and manage drop-down lists - Microsoft Support
Select the cells that you want to contain the lists. · On the ribbon, click DATA > Data Validation. · In the dialog,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found