jmd1002
jmd1002

Reputation: 45

Selecting a certain dropdown element using xpath (or better alternative)

How would I select a certain element in this drop down list.

<li role="presentation" ng-repeat="match in $matches" ng-class="{active: $isActive($index)}" class="ng-scope active">
    <a style="cursor: default" role="menuitem" tabindex="-1" ng-click="$select($index, $event)">
        <!-- ngIf: $isMultiple && $isActive($index) -->
            <i class="glyphicon glyphicon-ok pull-right" ng-if="$isMultiple &amp;&amp; $isActive($index)"></i>
        <!-- end ngIf: $isMultiple && $isActive($index) --> 
        <span ng-bind="match.label" class="ng-binding">Streamer</span>
    </a>
</li> 

I tried this

element(by.model('selectedAvailable')).click();
element(by.xpath('..//ul//li[1]')).click().

and this:

element(by.repeater('match in $matches').row(0)).click();

Upvotes: 2

Views: 147

Answers (2)

alecxe
alecxe

Reputation: 474001

I would filter() it, assuming you know the "Streamer" label and want to select it:

var matches = element.all(by.repeater('match in $matches')); 
matches.filter(function (match) {
    return match.element(by.binding("match.label")).getText().then(function (text) {
        return text === "Streamer";
    });
}).first().click();

Or, in a similar fashion with evaluate() instead of getText():

var matches = element(by.repeater('match in $matches')); 
matches.filter(function (match) {
    return match.evaluate("match.label").then(function (label) {
        return label === "Streamer";
    });
}).first().click();

Upvotes: 1

Florent B.
Florent B.

Reputation: 42528

An alternative would be to use by.cssContainingText :

element(by.cssContainingText('[ng-repeat="match in $matches"]', 'Streamer')).click();

Upvotes: 2

Related Questions