How to close the browser after completing a download?

前端 未结 3 1066
一向
一向 2021-01-04 08:28

How to make browser closed after completing download?

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

browser = webdriver         


        
3条回答
  •  别那么骄傲
    2021-01-04 08:45

    You can use the pause command:

    pause ( waitTime )
    

    Wait for the specified amount of time (in milliseconds)

    http://release.seleniumhq.org/selenium-core/1.0/reference.html#pause

    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.
    
    pause (10000) # pause/sleeps for 10 seconds
    
    browser.quit()
    

提交回复
热议问题