完成下载后如何关闭浏览器? [英] How to close the browser after completing a download?

查看:307
本文介绍了完成下载后如何关闭浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完成下载后如何关闭浏览器?

How to make browser closed after completing download?

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

browser = webdriver.Firefox()
browser.get(any_url)
browser.find_elements_by_xpath('//input[@value="Download"]').click()

# The program start downloading now.

# HERE WHAT IS THE CODE?

browser.quit()

我只想在完成下载后关闭浏览器.

I want to close the browser only after completing the download.

推荐答案

您可能要在关闭浏览器之前使用以下代码.

You may want to use the below piece of code right before you close the browser.

time.sleep(5)#在关闭浏览器之前留出时间来完成任务.你 可能会将秒数增加到10或15,基本上是时间 需要下载,否则转到下一步 立即.

time.sleep(5)# Gives time to complete the task before closing the browser. You may increase the seconds to 10 or 15,basically the amount of time required for download otherwise it goes to the next step immediately.

browser.quit()

这篇关于完成下载后如何关闭浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆