2

I am expecting a pop-up upon closing the browser. For example, when you are shopping and you have items in cart and in the middle of the checkout process, you wanted to close the tab/browser, at that time the site should give you a pop-up asking "Are you sure you want to leave?" or something similar!

I'm using Selenium with python.

When I do, driver.close() it just closes the browser. It does not give any pop up.

Is there any other method that I can use?

2
  • Instead of closing the browser all together, try using Key commands which simulate browser closing - Ctrl + W shortcut is one way. Or can you give me an example, where you observe this. Commented Aug 27, 2015 at 4:02
  • It is depends on site I think , Have you seen it for any site and in any browser? Commented Aug 27, 2015 at 7:24

1 Answer 1

2

Make sure you have a JavaScript popup handler for your test before closing the browser.

browser = webdriver.Firefox()

browser.get("http://abc.com")

try:

alert = browser.switch_to_alert()
alert.accept()  # If you don't want to accept it it's alert.dismiss()
browser.close()

else:

print("No popup")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.