使用Selenium Python单击具有相同ID的菜单项

2024-10-01 07:51:30 发布

您现在位置:Python中文网/ 问答频道 /正文

下面是我的HTML代码片段和我尝试的代码。我需要单击集成控制台菜单项。我试着像下面这样,但什么也没有发生,也没有错误。请帮助我使用标签内的文本选择特定的菜单项。你知道吗

driver.find_element_by_xpath(".//td[contains text(),'Integrated Consoles']").click()

HTMl示例代码段

<td nowrap="" id="MENU_TD110">&nbsp;&nbsp;&nbsp;&nbsp;Integrated Consoles&nbsp;</td>
<td nowrap="" id="MENU_TD110">&nbsp;&nbsp;&nbsp;&nbsp;System Information&nbsp;</td>
<td nowrap="" id="MENU_TD110">&nbsp;&nbsp;&nbsp;&nbsp;More Tools&nbsp;</td>

Tags: 代码文本idhtmldriver错误标签td
1条回答
网友
1楼 · 发布于 2024-10-01 07:51:30

contains方法中缺少括号(),请按如下方式括起来,然后尝试-

driver.find_element_by_xpath(".//td[contains(text(),'Integrated Consoles')]").click()

相关问题 更多 >