Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Selenium UnexpectedAlertPresentException

Tags:

I am running basic CRUD tests with python and lettuce using selenium webdriver.

All of my other tests run fine, but when I click "Delete", there is a modal dialog which asks the user to confirm that they want to delete that user. The moment the popup appears, I get the exception below. I have wasted 2 hours trying to get this to work. I would imagine there is a simple fix.

 File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 164, in check_response     raise exception_class(message, screen, stacktrace) UnexpectedAlertPresentException: Message: u'Modal dialog present' ; Stacktrace:      at nsCommandProcessor.prototype.execute (file:///tmp/tmpeV2K89/extensions/[email protected]/components/command_processor.js:11520:13) 

The line in steps.py that is throwing the error is this.

  world.browser.find_element_by_link_text("Delete User").click() 

And the html for that element is this.

<a href="/users/5910974510923776/delete" onclick="return confirm('Are you sure you want to delete this user?');">Delete User</a> 
like image 403
andygimma Avatar asked Feb 08 '15 18:02

andygimma


People also ask

Does Python 3.9 support selenium?

Selenium 3 is incompatible with Python 3.9 #8762.

How do you pass cookies in selenium Python?

In selenium you can get and set cookies with the methods get_cookies() and add_cookie(). Related course: Selenium Web Automation Course & Examples.

How do you get Textcontent in selenium?

New Selenium IDE It ignores the trailing and leading spaces. First of all we need to identify the element with help of any of the locators like id, class, name, xpath or css and then apply getText() method on it to get the text content of the element.


1 Answers

You need to switch to the alert and accept it:

world.browser.find_element_by_link_text("Delete User").click() alert = world.browser.switch_to.alert alert.accept() 
like image 90
alecxe Avatar answered Sep 18 '22 06:09

alecxe