1

I have written a code to automate the login process by passing credentials in python and using selenium web driver. So, once the login is done, then the user will need to carry out some task and then he will be the one closing the browser, on closing the browser manually, is it possible to end the chromedriver process as well?

Dran
  • 21
  • 4
  • 1
    Hi, the associated thread isn't what I am looking for. It's the opposite. In the associated, the question is to leave the browser open and close the driver, but I dnt want to do that. I want to only close the driver when the browser is closed. I dnt know how to reopen my question.I am not sure how what I am asking is a duplicate of the associated thread. Both are for different purpose. – Dran Aug 03 '20 at 22:51

2 Answers2

2

I dont think it is a good idea closing the browser manually. When you do it, you will get an Exception, maybe with message "timed out connecting to Chrome..." or something, because seleniumdriver instance is still running but chrome has gone.
I strongly suggest replacing this step by driver.quit.

BUT

If you really want to close the browser manually, maybe you can try to KILL the chromedriver process after that.
A demo in Java On Windows, like this:

Runtime.getRuntime().exec("taskkill /F /IM chromedriver.exe");
Peter Quan
  • 788
  • 4
  • 9
  • Hi, thank you for responding but I want to pause the script and then when the browser chrome.exe is not there, then only I want to kill the chromedriver process.. Is that possible? – Dran Aug 04 '20 at 00:17
0

You don't need close manually , you can use close() method in selenium

driver.close(); 

The Close() method closes the currently open browser window, which has the WebDriver's focus. All other browser windows remain open, and the webdriver's instance remains open and usable too. The Quit() closes all browser windows, and further disposes of the WebDriver instance.

Al Imran
  • 882
  • 7
  • 29
Justin Lambert
  • 940
  • 1
  • 7
  • 13
  • I understand but the thing is I am trying to automate the logging in process for an app, and I want to pause the script until it detects there is no chrome.exe, then to run it and close the driver. I have tried the close and quit, but it closes the browser after its done what is supposed to do and then close the browser but here I need the browser inorder to complete tasks etc after the logging in was done.Can I use threading in this scenario? And wait for event of Chrome.exe to close and then to run the rest of the script that would be to close the driver? – Dran Aug 03 '20 at 15:34
  • I used to use autoit and there is a similar function called winwaitclose in it but,using autoit for chrome automation also requires chromedriver and its pretty slow when compared to python and selenium setup. – Dran Aug 03 '20 at 15:39