0

I'm testing if a website has thrown an error and I myself get an error to see if this happens. So far I am just seeing if a button is clickable so if the button is not clickable/not displayed, then the program is okay to proceed. But if an error is there I need to return a value.

try:
    dismissBtn = WebDriverWait(driver, 2).until(EC.element_to_be_clickable((By.XPATH, "//input[@value='Dismiss this error']")))
    print("Reg Error Button is clickable")
finally:
    print("No error") 

The error is below

dismissBtn = WebDriverWait(driver, 2).until(EC.element_to_be_clickable((By.XPATH, "//input[@value='Dismiss this error']")))
  File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:

HTML Code is below

<div id="6823e3dd-d694-4a3e-99ae-6c074e3af73d" class="unite-error-panel errorPanel unite-component">
    <span class="unite-h1-no-image">An error occurred.</span>
      <ul>
      
        <li>We are unable to connect to our servers right now. Please try again later.</li>
      
      </ul>
    <div id="8977e4fa-bb61-4a51-8b56-5e051b7f95d1" class="unite-error-code" style="display: none;"> {"code":"GENERIC","httpStatus":0}</div>
    <div id="0b57d2f0-a8c4-4b7e-8095-ae09054cb053" class="unite-error-close">
      <input type="button" value="Dismiss this error">
    </div>
</div>

Is there another way I can go around this?

Code Collector
  • 97
  • 1
  • 1
  • 8

1 Answers1

0

The relevant text based HTML of the element would have helped us to analyze if the Locator Strategy you are using identifies the desired element uniquely. Assuming the element is uniquely identified, as it is a error message:

Perhaps increasing the waiting time from 2 seconds to 5 seconds will solve the issue.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I've updated the html code if you would like to take a look. The error doesn't always show which is good, but when it does show I would like the program to handle it. – Code Collector Jan 26 '21 at 02:32