[英]Selenium: Quit Python script without closing browser
I use the following to handle the situation where Ctrl + C is used to terminate a running Python script. 我使用以下内容来处理Ctrl + C用于终止正在运行的Python脚本的情况。
except KeyboardInterrupt:
print "ABORTED"
However, this also terminates my Selenium WebDriver
browser. 但是,这也终止了我的Selenium WebDriver
浏览器。
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 . 我通常做的是通过Ctrl + Z暂停脚本。 This unfortunately often causes the browser to freeze and not respond. 不幸的是,这经常导致浏览器冻结而不响应。
You can replace CTRL+C+ sys.exit()
with quit()
method to terminate Python
script without closing browser session. 您可以使用quit()
方法替换CTRL + C + sys.exit()
以终止Python
脚本而不关闭浏览器会话。 Just use following form: 只需使用以下表格:
user_choice = raw_input('Please click ENTER button to close application')
if not user_choice:
print "ABORTED"
quit()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.