Jorge
Jorge

Reputation: 305

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

We're doing automation scripts using the following:

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?

Upvotes: 3

Views: 17598

Answers (2)

Ahmed Helmey
Ahmed Helmey

Reputation: 1

I have just had a similar issue using Selenium. One of the reasons this could occur when trying to leave the current page you're working on without having to save. Selenium can't deal with additional dialogues.

One example of additional dialogues is when you're typing a post and you're trying to navigate to a different page without saving or publishing the post you're typing. In this case, the navigation code is executed however you haven't actually left the page.

If there is a button to be clicked, make sure to click it before attempting to leave the page. Do not attempt to force close the page while there is an additional dialogue because that force stop will lead to a failure the next time you try to get a new instance of 'driver'.

Upvotes: 0

Adrian H
Adrian H

Reputation: 317

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.

Upvotes: 0

Related Questions