Selenium: Quit Python script without closing browser

让人想犯罪 __ 提交于 2019-11-30 05:19:55

问题


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.


回答1:


You can replace CTRL+C+sys.exit() with quit() method to terminate Python script without closing browser session. Just use following form:

user_choice = raw_input('Please click ENTER button to close application')
if not user_choice:
    print "ABORTED"
    quit()


来源:https://stackoverflow.com/questions/36334983/selenium-quit-python-script-without-closing-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!