Python selenium webdriver select href 选择部分文本

问题描述

我在 Ubuntu 20.04 上使用 Python 3.8.5。在 chrome 上使用 selenium webdriver,我想通过指定包含在此元素中的 licenceId 编号 (1467250) 来下载附件:

<a xmlns="http://www.w3.org/1999/xhtml" href="#" onclick="if(typeof jsfcljs == 'function'){jsfcljs(document.forms['myApplicationsResultsForm'],'myApplicationsResultsForm:searchResultsTable:0:j_id339:0:j_id340,myApplicationsResultsForm:searchResultsTable:0:j_id339:0:j_id340,licenceId,1467250,statusHistoryId,2600790,fileName,ROL_1467250_20200817-142839.pdf,attachmentType,ROL','');}return false" class="pageLink"><img src="/oplinc2/images/pdf.jpg" alt="ROL_1467250_20200817-142839.pdf" height="24" style="border-width: 0px;" title="ROL_1467250_20200817-142839.pdf" width="24" /></a>

我可以通过单击 css_selector 来下载此链接:

pdf = driver.find_element_by_css_selector('#myApplicationsResultsForm\:searchResultsTable\:0\:j_id335 > a')

pdf.click()

我可以使用元素中的部分文本来定位和下载附件,例如。 licenceID,1467250?这些附件有很多。我尝试了部分文本示例 from the docs 但这对我不起作用:

>>> driver.find_element_by_partial_link_text('1467250')

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"partial link text","selector":"1467250"}

编辑 这个问题类似于@Ajay 指向 this solution 的链接,但此元素的 href 略有不同。仍然不确定如何访问 onclick

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)