Reputation: 1
From this code as below:
<a href="javascript:;" id="cTDQo7-a" class="z-menu-cnt z-menu-cnt-img"><span id="cTDQo7-img" class="z-menu-img"></span> payment</a>
<span id="cTDQo7-img" class="z-menu-img"></span>
"payment"
I would like to get locator use keyword contains but the word "payment" is a lot of the page such as payment1,payment2,payment3 And id is not unique.
I tried to use the code below but not work for me.
//a[contains(.,'payment')]
//span[@class='z-menu-img'] [contains(.,'payment')]
//span[@class='z-menu-img'] and [contains(.,'payment')]
//span[@class='z-menu-img'] contains(.,'payment')
Upvotes: 0
Views: 1472
Reputation: 14135
Option 1 : Use the other attributes in combination with text
//a[@class='z-menu-cnt z-menu-cnt-img' and normalize-space(.)='payment']
Option 2: Specify the position if you have multiple elements without unique attributes/path
(//a[contains(.,'payment')])[1]
The second xpath will identify the first occurrence of the link contains text 'payment'. You can change the tagname and index based on your interest.
Upvotes: 1