繁体   English   中英

Python selenium webdriver 元素未找到

[英]Python selenium webdriver element not found

我正在研究 web 自动化项目之一,我卡在一个按钮上,我的 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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM