简体   繁体   English

Selenium:退出Python脚本而不关闭浏览器

[英]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.

相关问题 Python Selenium:空闲时退出浏览器 - Python Selenium: Quit Browser if Idle Python 和 Selenium - 关闭所有选项卡而不关闭浏览器 - Python and Selenium - Close all tabs without closing the browser python中的selenium,如何在不关闭浏览器的情况下忽略错误 - selenium in python, how to ignore errors without closing the browser 为什么我的 Selenium 浏览器在 Python 中自行关闭 - Why is my Selenium browser closing itself in Python Python Selenium-[错误5]尝试退出浏览器实例时拒绝访问 - Python Selenium - [Error 5] Access is denied when trying to quit a browser instance 如何在不关闭和打开每个元素的浏览器的情况下单击并打开 python selenium 元素中的对象集合 - How do I click and open a collection of objects in an element in python selenium without closing and opening the browser for each element 如果设置了firefox_profile,则python selenium driver.quit()无法退出firefox浏览器 - python selenium driver.quit() can not quit firefox browser if firefox_profile setted “Firefox意外退出。”在Python中运行基本的Selenium脚本时 - “Firefox quit unexpectedly.” when running basic Selenium script in Python 有没有一种方法可以退出selenium驱动程序而不结束会话? (蟒蛇) - Is there a way to quit selenium driver without ending the session? (python) python中的Selenium - 打开testprogamm后立即关闭浏览器 - Selenium in python - Browser closing immediately after open testprogamm
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM