Home > Net >  How to locate a link with an img on the same row in a grid with xpath
How to locate a link with an img on the same row in a grid with xpath

Time:07-09

I need to click a link in a grid that contains a particular img on the same row. I can easily find the correct img I want with:

//img[@src='./assets/images/not_evaluated.svg'].

However, when I issue the click with it, it doesn't work because the image is not clickable. However, the same row contains the link I want to click. The xpath to the clickable link is:

//a[@class='veracodelink']//span[contains(text(),'Static Scan')].

I need to combine these 2 xpaths to get the correct link to click. I have tried many different things and combinations, but nothing seems to work.

CodePudding user response:

Assuming that the image and the link are inside the same tr element, you could combine them like this:

//tr[.//img[@src='./assets/images/not_evaluated.svg']]//a[@class='veracodelink']//span[contains(text(),'Static Scan')]

Explained: //tr[...] here selects the correct row containing the image, and the rest then selects the clickable element relative to that.

If they are inside something else than tr, adjust accordingly.

CodePudding user response:

So I finally figured this out myself: The xpath I needed is:

//div//vc-link//a[@class='veracodelink']//span[contains(text(), 'Static Scan')][../../../../../..//img[@src='./assets/images/not_evaluated.svg']]

  • Related