#encoding=utf-8 import unittest from selenium import webdriver import time from selenium.webdriver.chrome.options import Options
class TestChromeDownload(unittest.TestCase):
def setUp(self):
# 创建Chrome浏览器配置对象实例
options = Options()
options.add_experimental_option("prefs",{
"download.default_directory" : r"d:\download",
"download.prompt_for_download" : False,
"download.directory_upgrade" : True,
"safebrowsing.enabled" : True
})
# 启动带有自定义设置的Chrome浏览器
self.driver = webdriver.Chrome(executable_path = "d:\\chromedriver",\
chrome_options = options)
def test_downloadFileByChrome(self):
url = "http://mirrors.hust.edu.cn/apache/zzz/mirror-tests/"
self.driver.get(url)
self.driver.find_element_by_partial_link_text("tar.gz").click()
time.sleep(20)
if name == "main": unittest.main()