2

I use safari driver in my tests automation. When I try to use driver.close() to close safari, there is always a popup "Are you sure you want to quit this site"?

How can I ignore the popup or disable the popup? I want the browser to close directly when I do driver.close.

I use selenium 3.4 and safari 11.0, and Java.

Here's my code:

SafariOptions options = new SafariOptions();
options.setUseCleanSession(true);
WebDriver driver = new SafariDriver(option);
driver.manage().window().maximize();
Giorgos Myrianthous
  • 36,235
  • 20
  • 134
  • 156
yue
  • 119
  • 1
  • 11
  • Did you try `Alert alert = driver.switchTo().alert(); alert.accept();`? – Fenio Jan 30 '18 at 11:24
  • Possible duplicate of [Selenium WebDriver how to close browser popup](https://stackoverflow.com/questions/6852732/selenium-webdriver-how-to-close-browser-popup) – JeffC Jan 30 '18 at 14:40

1 Answers1

1

While automating through Selenium as per the best practices you should invoke the quit() method within the tearDown() {}. Invoking quit() DELETEs the current browsing session through sending "quit" command with {"flags":["eForceQuit"]} and finally sends the GET request on /shutdown EndPoint.

So instead of :

driver.close();

Use :

driver.quit();

You will find a detailed discussion in Selenium : How to stop geckodriver process impacting PC memory, without calling driver.quit()?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352