【发布时间】:2021-02-02 17:32:44
【问题描述】:
在我的程序中,我得到了这样的东西:
driver = webdriver.Chrome(options=Options()) #calling the driver
driver.get(website) #opening the website
try:
while True:
do_something() #Here I do a couple of things
except KeyboardInterrupt:
#When I'm done with the while loop above(the goal is to be able to stop at any point of the loop) I use ctrl+c
pass
#Here the program continues but selenium closes the window even though I didn't call for driver.quit().
虽然它成功停止了 while 循环并且不结束程序本身,但 selenium 会关闭窗口浏览器。有没有办法防止 selenium 关闭窗口?
【问题讨论】:
-
如果您没有告诉 Selenium 关闭浏览器,它不会关闭它。我们需要查看更多您的代码。
-
对不起,我编辑了原始帖子并添加了更多信息。关键是我想在任何时候成功地离开 while 循环。我用 ctrl+c 实现了这一点,但这也关闭了窗口浏览器,我想保持打开状态。
-
我试过了,但由于某种原因,它甚至没有打开浏览器并立即崩溃。
-
“我想在任何时候成功退出while循环”是什么意思,是有特定条件,还是随机结束
标签: python selenium selenium-webdriver try-catch keyboardinterrupt