I am rtying to find a button in a date selector, I tried this:
driver.find_element_by_xpath("//input[@day='5']")
the element is :
<button class="active" day="5" month="10" year="2021" aria-describedby="tooltiptext_5">5</button>
the clander look like this: clickhere
the error msg when it trying to find the element:
[17756:20660:1004/113550.831:ERROR:chrome_browser_main_extra_parts_metrics.cc(22
8)] crbug.com/1216328: Checking Bluetooth availability started. Please report if
there is no report that this ends.
[17756:20660:1004/113550.831:ERROR:chrome_browser_main_extra_parts_metrics.cc(23
1)] crbug.com/1216328: Checking Bluetooth availability ended.
[17756:20660:1004/113550.832:ERROR:chrome_browser_main_extra_parts_metrics.cc(23
4)] crbug.com/1216328: Checking default browser status started. Please report if
there is no report that this ends.
[17756:20660:1004/113550.860:ERROR:chrome_browser_main_extra_parts_metrics.cc(23
8)] crbug.com/1216328: Checking default browser status ended.
Traceback (most recent call last):
File "
", line 26, in <module>
func()
File "
", line 22, in func
driver.find_element_by_xpath(DATE)
File "
ib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_elem
ent_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "
ib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_elem
ent
return self.execute(Command.FIND_ELEMENT, {
File "
ib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "
ib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_
response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Una
ble to locate element: {"method":"xpath","selector":"//input[@day='5']"}
(Session info: chrome=94.0.4606.71)
thanks a lot Adam.
CodePudding user response:
You might be getting this error since you have given an input element for the xpath even though it's a button. So try this.
btn = driver.find_element_by_xpath("//button[@day='5']")