I am working my way through a website making a reservation. Upon completing the reservation a box pops up (that looks like an alert) titled request complete (html follows).
I have tried to access it as if it was an alert and consistently get a no alert present exception. I have read all i can find and learned that recent HTML changes allow items to be displayed that look like pop ups but are not (see https://www.eviltester.com/webdriver/faqs/why-does-selenium-not-work-with-this-alert/#:~:text=Q: “Why does Selenium not work with my,of the web has changed. HTML has changed.).
AS a result i have changed the python code to use a find_element(By.CLASS_NAME) syntax and i am able to find the element (code attached). sleep(5) try: br.find_element(By.CLASS_NAME, "ui-button-text") print ("found the continue button") return 1 except NoSuchElementException: print ("Did not find continue button") return 0
However when i try to execute a click as follows:
sleep(5)
try:
br.find_element(By.CLASS_NAME, "ui-button-text").click()
print ("found the continue button")
return 1
except NoSuchElementException:
print ("Did not find continue button")
return 0
I get an element not interactable message.
Exception in thread Thread-1 (tee_time_thread):
Traceback (most recent call last):
File "C:\MyStuff\Python310\lib\threading.py", line 1016, in _bootstrap_inner
self.run()
File "C:\MyStuff\Python310\lib\threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "C:\MyStuff\Python310\Projects\Automated Tee Times\New Automated 22-09-14.py", line 1456, in tee_time_thread
result = commit_time(self, br, thread)
File "C:\MyStuff\Python310\Projects\Automated Tee Times\New Automated 22-09-14.py", line 330, in commit_time
br.find_element(By.CLASS_NAME, "ui-button-text").click()
File "C:\MyStuff\Python310\Projects\updatefoursomes\lib\site-packages\selenium\webdriver\remote\webelement.py", line 88, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\MyStuff\Python310\Projects\updatefoursomes\lib\site-packages\selenium\webdriver\remote\webelement.py", line 396, in _execute
return self._parent.execute(command, params)
File "C:\MyStuff\Python310\Projects\updatefoursomes\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 435, in execute
self.error_handler.check_response(response)
File "C:\MyStuff\Python310\Projects\updatefoursomes\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=105.0.5195.102)
I have tried everything i can think of and looked at a lot of questions/websites to try to figure out what i am missing. Any help would be greatly appreciated. Thanks in advance.enter code here
CodePudding user response:
You might need to wait for element to be clickable. Use Webdriverwait() and wait for element to be clickable and use the following xpath.
WebDriverWait(br,20).until(EC.element_to_be_clickable((By.XPATH,"//button[.//span[text()='Continue']]"))).click()
You need to import below libraries.
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
Using above solution, if you are still getting element not interactable
then try with javascripts executor or action class.
elementbtn=WebDriverWait(br,10).until(EC.element_to_be_clickable((By.XPATH,"//button[.//span[text()='Continue']]")))
driver.execute_script("arguments[0].click();", elementbtn)
CodePudding user response:
Used wait with element to be clickable and the right XPATH. Thanks so much for your direction - worked with just a little fine tuning.Just curious and timed it out - it takes .54 seconds to be addressable - seems like a long time...
WebDriverWait(br,10).until(EC.element_to_be_clickable((By.XPATH, "/html/body/div[5]/div[4]/div/button/span"))).click()