3

Drop-down contain the ng-model ="text.abc" and contain visible text="Test":

<md-select id="select_55" class="ng-pristine ng-untouched ng-valid ng-valid-required" required="" aria-label="queuingModel: SKILL_GROUP" ng-model="text.abc" md-on-close="vm.changeQueue(vm.queue.resourcePoolType)" name="resourcePoolType" tabindex="0" aria-disabled="false" role="listbox" aria-expanded="false" aria-multiselectable="false" aria-owns="select_container_56" aria-required="false" aria-invalid="false" style="">
<md-select-value id="select_value_label_51" class="md-select-value">
<span>
<div class="md-text ng-binding">SKILL_GROUP</div>
</span>
<span class="md-select-icon" aria-hidden="true"></span>
</md-select-value>

I cannot use this code:

element(by.model('text.abc')).$('[value=" ?"]').click(); 

I do not have value of drop-down.

What should be the protractor code for drop-down in this case?

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195

3 Answers3

2

You can select a value by it's text:

var optionToSelect = "SKILL_GROUP";

var dropdown = element(by.model('text.abc'));
dropdown.click();

dropdown.element(by.xpath(".//div[contains(@class, 'md-text') and . = '" + optionToSelect + "']")).click();
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Now this error occur Failed: Element is not clickable at point (703, 415.5). Other element would receive the click:
    – Iqra Shahid May 23 '16 at 05:55
2

How about...

element(by.id(dropdownList)).sendKeys("value");

or

element(by.model(dropdownModel)).sendKeys("value");
findlayc
  • 136
  • 5
  • I did not understand this.When(/^I select string "([^"]*)" from the dropdown menu with id "([^"]*)"$/, function(string, dropdownList, next) statement can you please elaborate it – Iqra Shahid May 23 '16 at 06:05
  • Apologies. I am used to using [Cucumberjs](https://github.com/cucumber/cucumber-js) to define my tests. I've updated my answer to remove the reference to cucumber – findlayc May 23 '16 at 09:39
1

Try this code.

// Select Category
element.all(by.model('dropdown')).each(function (eachElement, index)
{
     eachElement.click();
     browser.driver.sleep(500);
     element(by.model('text.abc')).click();
     browser.driver.sleep(500);
});

Hope this helps. :) See answers here for more information.

Community
  • 1
  • 1
Manuli
  • 1,203
  • 4
  • 20
  • 43