Reputation: 764
This question might be easy for some people. I want to click on a link based on href value and text in link.Below is what i am using to search for text in link.
var elementselected = this.coinDataTable.element(by.css('a[href*='+CoinLink+']'));
I tried below code but it is not working. Can someone please suggest correct usage?
var elementselected = this.coinDataTable.element(by.css('a[href*="'+CoinLink+'"][text='CoinText'));
OR
var elementselected = this.coinDataTable.element(by.css('a[href*='+CoinLink+']')).element(by.linkText('CoinText'));
or
var elementselected = this.coinDataTable.element(by.linkText('CoinText')).element(by.css('a[href*='+CoinLink+']'));
This link is inside a table. Below is HTML for whole row. There are 2 links in this row. I want to select 2nd one which has CoinText in it.
<tr>
<td><a href="CoinLink"><img border="0" src="../../../images/pc_cdlibrary_side_icon_img_lighterbg.gif"></a></td>
<td>1C</td>
<td>MS</td>
<td><a href="CoinLink">CoinText</a></td>
<td>$15</td>
<td>S-12 </td>
<td>B-21</td>
</tr>
Upvotes: 1
Views: 2879
Reputation: 1
This code helps me to solve the issue
element(by.css('a[href*="CoinLink"]')).getText()).toContain('CoinLink')
Upvotes: -1
Reputation: 42528
You could use the by.cssContainingText
to find the element by text and attribute:
by.cssContainingText('[href*="CoinLink"]', 'CoinText')
Upvotes: 2