So you can use the following:
driver.close()
Close the browser (emulates clicking the close button)
driver.quit()
Exit the browser (emulates the choice of the exit option)
driver.dispose()
Exit the browser (try closing each tab and exit)
However, if you still have problems with instance freezes (like me), you can also kill the instance. To do this, you need the PID of the Chrome instance.
import os import signal driver = webdriver.Chrome() driver.get(('http://stackoverflow.com')) def get_pid(passdriver): chromepid = int(driver.service.process.pid) return (chromepid) def kill_chrome(thepid) try: os.kill(pid, signal.SIGTERM) return 1 except: return 0 print ("Loaded thing, now I'mah kill it!") try: driver.close() driver.quit() driver.dispose() except: pass kill_chrome(chromepid)
If thereโs a copy of Chrome left after that, I'll eat my hat. :(
Rue Lazzaro Oct 22 '18 at 18:24 2018-10-22 18:24
source share