python - 未找到 Python selenium webdriver 元素
问题描述
我正在开发一个网络自动化项目,但我卡在一个按钮上,我的 python 程序无法找到该过滤器按钮的元素
该按钮的 html 代码是
<a role="button" class="list_filter_toggle icon-filter btn btn-icon" tabindex="0"
title="" id="task_filter_toggle_image"
aria-controls="taskfilterdiv"
aria-expanded="false" data-original-title="Show / hide filter"><span
class="sr-only">Show / hide filter</span></a>
我的代码是
btn=browser.find_element_by_xpath("//*[contains(text(), 'Show / hide filter'")
btn.click()
错误信息
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an
element with the xpath expression //*[contains(text(), 'Show / hide filter' because of the following
error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[contains(text(), 'Show /
hide filter'' is not a valid XPath expression.
(Session info: chrome=89.0.4389.82)
Stacktrace:
Backtrace:
请帮帮我,我需要点击按钮但找不到按钮元素
解决方案
from selenium import webdriver
website = "www.stackoverflow.com"
driver = webdriver.Firefox()
driver.get(website)
e = driver.find_element_by_xpath("//*[text()='Show / hide filter']")
print(e)
推荐阅读
- laravel - 如何使用 laravel 发送电子邮件?
- reactjs - 在 useEffect 中使用 useState 值而不使状态更新 useEffect
- javascript - 为什么我不能在事件处理程序中访问我的功能组件的道具?
- linux - 打印所有启用的驱动程序的 Kconfig 帮助
- reactjs - react Redux调度中何时更新父道具?
- javascript - 错误:写入 EPROTO 34557064:error:100000f7:SSL 例程:OPENSSL_internal:WRONG_VERSION_NUMBER:../../third_party/boringssl/src/ssl/tls_record.cc:242:
- python - 将列表列表作为列添加到python中的现有数据框
- swift - 如果与正则表达式相比,为什么在更大的字符串中找不到我的搜索字符串?
- c# - 当 MaxNodeCount 大于 1 时,MSBuild ver.16 运行数百个 MSBuild 进程
- firebase - 错误:HTTP 错误:404,尝试部署函数时未找到