I use the following to handle the situation where Ctrl + C is used to terminate a running Python script.
except KeyboardInterrupt:
print "ABORTED"
However, this also terminates my Selenium WebDriver
browser.
Is there a way to terminate the script and keep the browser alive, so that I can continue using it?
What I usually do instead, is to pause the script via Ctrl + Z. This unfortunately often causes the browser to freeze and not respond.
driver.quit()
.sys.exit()
close browser session despite of callingdriver.quit()
– Mckalesys.exit()
is in there because Ctrl+C will make everything exit anyway. – Barca