1

Need to get xpath for the following. It is not accpeting with anchor tag as I have several anchor tags with same random auto generated ID.

The only difference I can pull with is text. How do I get that

.//tr[@class='r ng-scope']/td[contains(@class,'v3details')]/a[contains(@id,'anchor')]

enter image description here

enter image description here

Sample HTML:

<tr class="r ng-scope" ng-repeat-start="category in resultSection.content.category" ng-init="randNum2=resultsCtrl.getRandom(); "> 
    <td class="v3details_td_text1_b0110" style="padding: 5px 30px;" colspan="2" width="100%"> 
        <a id="anchor__" class="v3_links ng-binding" style="text-decoration: none;" href="" ng-click="resultsCtrl.setSwapThisTextLink(randNum1,randNum2)"> 
            <span id="icon_res_det_catg_b1967e0b2482995_651b54721c2b232"> 
                <img src="images/spacer.gif" height="1" width="6"/> 
            </span>
            DeviceInfo 
        </a> 
    </td> 
</tr>
  • It looks like you mistyped the HTML you added - I took a guess at where the inner span was supposed to end but as typed it was malformed. – Kate Paulk Feb 19 at 18:33
  • No, I copy pasted the code as it is, IT has Span tag and outside span there is Text DeviceInfo. – user37193 Feb 19 at 19:09
1

If you have text of anchor than you should try //a[contains(text(),'Add New Button']

or findElement(By.partialLinkText("partialLinkText"))

  • Something like this should work. I'd recommend asking the developers to better decorate elements for testing though – Topperfalkon Jul 20 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.