Python 3.x Selenium不会单击,没有名称、id或类

Python 3.x Selenium不会单击,没有名称、id或类,python-3.x,selenium-webdriver,Python 3.x,Selenium Webdriver,我想SeleniumWebDriver点击这个链接,这样我就可以继续我的项目了。这是我的密码。没有错误,但它不会单击链接 x = driver.find_element_by_xpath('/html/body/table[2]/tbody/tr[2]/td/span/ a[7]') x.click() 这是HTML <tr> <td width="100%"> <span style="white-space: nowrap">

我想SeleniumWebDriver点击这个链接,这样我就可以继续我的项目了。这是我的密码。没有错误,但它不会单击链接

x = driver.find_element_by_xpath('/html/body/table[2]/tbody/tr[2]/td/span/  
a[7]')
x.click()
这是HTML

<tr>
  <td width="100%">
    <span style="white-space: nowrap">
      <a href="#">
        <img src="https://staffmate.com/imagessm/OEA_sm_lt.gif" border="0" width="125" height="36">
      </a>
      <a href="#">
        <img src="https://staffmate.com/imagessm/OPOS_sm_lt.gif" border="0" width="125" height="36">
      </a>
      <a href="#">
        <img src="https://staffmate.com/imagessm/OCTR_sm_lt.gif" border="0" width="125" height="36">
      </a>
      <a href="#">
        <img src="https://staffmate.com/imagessm/OCL_sm_lt.gif" border="0" width="125" height="36">
      </a>
      <a href="#">
        <img src="https://staffmate.com/imagessm/OVEN_sm_lt.gif" border="0" width="125" height="36">
      </a>
      <a href="#">
        <img src="https://staffmate.com/imagessm/OEV_sm_dk.gif" border="0" width="125" height="36">
      </a>
      <a href="eprintreports.php?eSessID=199495633810875522501415473608154261624185901388039708769020171218111124">
        <img src="https://staffmate.com/imagessm/PREP_sm_lt.gif" border="0" width="125" height="36">
      </a>
      </span>
    </td>
</tr>


我想点击第七个链接。我直接从Chrome的检查工具中复制了xpath。我知道绝对xpath是不可靠的,但当没有类名、id或名称时,我还能使用什么呢?非常感谢您的帮助。

请尝试以下xpath:

"//a[contains(@src, 'PREP')]"
单击
标记可能无法获取所需的输出。您需要深入到<代码>属性> <强> >代码> PREP> /代码> <强>,但理想的是我们应该考虑属性的完全<代码>值< /> >


你能分享这个URL吗?我已经添加了这个URL。这个URL似乎还没有出现在描述中,你能添加它吗?这样我们就可以帮助你了。谢谢你的帮助。不幸的是,这会导致一个错误:没有这样的元素。这与我尝试通过链接文本查找元素时的错误相同。当我通过IDE:print(driver.page\u source)查看源代码时,该链接不可单击。这可能是问题所在吗?谢谢你的帮助。不幸的是,这会导致一个错误:没有这样的元素。这与我尝试通过链接文本查找元素时的错误相同。当我通过IDE:print(driver.page\u source)查看源代码时,该链接不可单击。这可能是问题所在吗?@Cameron你能详细解释一下链接不可点击是什么意思吗。请用更多的outerHTML更新这个问题。
driver.find_element_by_xpath("//td/span//a/img[contains(@src,'https://staffmate.com/imagessm/PREP_sm_lt.gif')]").click()