How to finish process 'Chrome.exe' when finishing script execution

Asked

Viewed 1,200 times

1

I implemented a script using Selenium that accesses some pages. The code is working exactly as expected.

My problem is when script finishes its execution which happens in two ways:

  • When the user closes the browser (Chromedriver)
  • When the user closes the command prompt or interrupts the script (Ctrl+C)

After the closure of the execution, the process 'Chrome.exe' remains active, making files continue to be used and locking them (you cannot delete/move/rename...).

I found out that there are commands to terminate these processes.

browser.close() will close only the current window.

browser.quit() close all open windows.

But I need to fire these methods at the right times, have triggers that trigger only when the user finishes the execution.

Any other idea/solution is welcome.

  • the process remains open in both cases? both with the user closing the window and closing terminal?

  • @Karlzillner yes, from the moment the webDriver is started driver = webdriver.Chrome(chrome_options=chrome_options), the process remains open in both cases.

  • The expection except (KeyboardInterrupt, SystemExit): can help you with Ctrl+C. Use browser.close() and the browser.quit() to finalize the process.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.