Rashmi Chauhan
Rashmi Chauhan

Reputation: 135

How to select dropdown option by matching text?

I want to select dropdown option by matching option text.

HTML code:

<li title="Add Page" class="dropdown-header ng-scope" data-ng-if="selectedPage">Add Page</li> 
<li title="Add page before the current page" data-ng-if="selectedPage" class="ng-scope">
<a data-ng-click="addPage(selectedPage, 'before')">Before Selected</a>   </li>
<li title="Add page after the current page" data-ng-if="selectedPage" class="ng-scope">
<a data-ng-click="addPage(selectedPage, 'after')">After Selected</a></li>

Upvotes: 0

Views: 107

Answers (2)

Chris Traynor
Chris Traynor

Reputation: 460

I've always used:

.click().sendKeys(); 

to select options from my drop downs. Haven't had a problem yet.

Upvotes: 0

alecxe
alecxe

Reputation: 474001

You can use by.xpath() and check the a element's text:

element(by.xpath('//li/a[. = "Before Selected"]')).click();

Or, by link text:

element(by.linkText("Before Selected")).click();

Upvotes: 2

Related Questions