Getting "Exception UnexpectedAlertPresentException: Alert Text: None" and then "Exception NoAlertPresent" when I try to handle that alert

Jorge picture Jorge · Feb 27, 2018 · Viewed 9.9k times · Source

We're doing automation scripts using the following:

  • behave==1.2.5
  • splinter==0.7.7
  • firefox headless browser

When navigating to a specific page, we're executing the following code:

browser = context.browser
selector_button_checkout = "//*[@id='cart']//div[contains(@class, 'button button-3 localizejs') and text()='CHECKOUT']"
with browser.get_iframe(0) as iframe:
    assert iframe.is_element_present_by_xpath(selector_button_checkout, wait_time=30)

We're getting this error:

packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
          raise exception_class(message, screen, stacktrace)
      selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: None
      Message:

Exception UnexpectedAlertPresentException: Alert Text: None
Message: 

Traceback (most recent call last):
selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: None
Message: 

Actually, there is no alert nor prompt shown in the web, but anyways we tried to handle it using the Splinter documentation present in here http://splinter.readthedocs.io/en/latest/iframes-and-alerts.html

and we get another exception which is NoAlertPresentException, so we're lost.

Any ideas?

Answer

Adrian H picture Adrian H · Apr 10, 2018

This might help: How to handle an Alert with "UnexpectedAlertBehaviour" capability in Selenium?

For us, we had Codeception with FacebookWebDriver, sometimes when you try to click or access a member that does not exist or is not visible it fails with the error above.

So go the the problem page and check if that element (css or xpath) is visible, clickable, etc. You can use the browser console, $() for query path and $x() for xpath.