Accessing what looks like a pop up but apparently isn't

Viewed 35

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). enter image description here

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%3A%20%E2%80%9CWhy%20does%20Selenium%20not%20work%20with%20my,of%20the%20web%20has%20changed.%20HTML%20has%20changed.).

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

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)

What am i missing?

1 Answers

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