I've got markup of the following format I'm attempting to work with using Selenium/Python:
<tr>
<td><a href="www.google.com">google</a></td>
<td>useless text</td>
<td>useless text2</td>
<td>useless text3</td>
<td><a href="needle@email.com">emailaddress</a></td>
</tr>
The idea being that given a known email address (part of the href
in the emailaddress td
), I can get to (and click) the a
in the first td
. It looks like xpath is the best choice to accomplish this with Selenium. I'm trying the following xpath:
//*[@id="page_content"]/table/tbody/tr[2]/td[2]/div/table[1]/tbody/tr/td[4]/a[contains(@href, "mailto:needle@email.com")]/../../td/a[0]
But I'm getting this error:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"xpathhere"}
I do know the xpath to get to the "needle@email.com" a is correct, as it's just copied from chrome dev tools, so the error must be with the part of the xpath after reaching the first a
element. Can anyone shed some light on the problem with my xpath?