简体   繁体   中英

Python selenium webdriver element not found

I am working on one of web automation project and i get stuck on one button my python program not able to find element for that filter button

html code for that button is

<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>

and my code is

btn=browser.find_element_by_xpath("//*[contains(text(), 'Show / hide filter'")
btn.click()

error message

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:

please help me, i need to click on button but not able to find button element

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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