Alen
Alen

Reputation: 65

Protractor - locate element by both className and text

I have a situation in my web application where some listed items do share common className that is used by our automated test suites. Now, I have to click on specific element and need to locate it by it's class and text of that element.

Here is an example:

<ul>
   <li class="autotest-list">Milk</li>
   <li class="autotest-list">Sugar</li>
   <li class="autotest-list">Candy</li>
</ul>

I need a way how to click on ie.Sugar. Something like this:

element(by.className('autotest-list').text('Sugar');

or this

element(by.className('autotest-list')&&text('Sugar');

Thank you all in advance!

Upvotes: 0

Views: 1646

Answers (2)

Vlad A
Vlad A

Reputation: 154

element(by.cssContainingText('.autotest-list','Sugar')

Upvotes: 2

eLRuLL
eLRuLL

Reputation: 18799

If you don't mind, you could use by.xpath:

element(by.xpath('li[@class="auto test-list" and text()="Sugar"]'))

Upvotes: 0

Related Questions