Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

python - Error when trying to detect if error has shown on website selenium

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:UsersUserAppDataLocalProgramsPythonPython39libsite-packagesseleniumwebdriversupportwait.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?

question from:https://stackoverflow.com/questions/65881211/error-when-trying-to-detect-if-error-has-shown-on-website-selenium

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...