0

I'm facing a problem with my selenium tests. I have a script that do some stuff and then close the browser When i do close the browser there is a popup message (screen shot attached) that I need to accept in order for the browser to close. My problem is that I tried many different idea but none worked. from switch.accept to dismiss() to javascriptExecutor an no luck. This is the method Im using to close the broswer. after this method is called then i get the popup than i need to close.

public static void closeDriver() throws InterruptedException{
     if(driver!=null){
        driver.quit();
        driver=null;
        log.info("The Browser was closed successfully");
    }
Krishnan Mahadevan
  • 14,121
  • 6
  • 34
  • 66
mbn217
  • 884
  • 7
  • 14
  • I cannot see any screenshot attached. Can you please attach it again? – Rabia Asif Apr 26 '18 at 06:26
  • I'm not sure how to attach the screen shot after a posting this but here is a link to an exact similar popup to mine: https://www.google.com/search?q=leave+page+stay+on+page+popup+selenium&client=firefox-b-1&source=lnms&tbm=isch&sa=X&ved=0ahUKEwiI7_XMudjaAhVJdt8KHWs-C0sQ_AUIDCgD&biw=1536&bih=767#imgrc=AvlMzX2lzgT8lM: – mbn217 Apr 26 '18 at 17:21

2 Answers2

0

Your scenario is little bit complex , as after closing the browser you want to interact with pop up.

Well your code :

if(driver!=null){
        driver.quit();
        driver=null;
        log.info("The Browser was closed successfully");
    }  

your driver instance would be closed after driver.quit(); line.

driver=null;
log.info("The Browser was closed successfully");  

should not be executed at all.

But if there are multiple instances of browser you've opened to do your testing, you may wanna switch to driver.close(); .and then try to handle the alert.

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
  • Yep exactly, the issue is that after closing the broswer then i have to interact with the popup, and it's too late there cause i called driver.quit() method. Even if i dont set driver =null it still wont work cause i already called that close method. Also, driver.close() doesnt work . Thanks for the reply though, I appreciate it. – mbn217 Apr 26 '18 at 17:12
  • I do have a workaround by using .vbs file to kill browser process instead of driver.close() but i dont want to use it.I want to see if there is any solution for it – mbn217 Apr 26 '18 at 17:17
0

This pop-up cannot be handled with any of selenium commands because it cannot be inspected. You will have to use AutoIt script for that. See the reference below which is for the authentication popup of browser

https://stackoverflow.com/a/47175309/7030563

Rabia Asif
  • 298
  • 3
  • 14