encoding = utf-8
from selenium import webdriver
import time, unittest
class TestDownLoad(unittest.TestCase):
def setUp(self) -> None:
“”“测试谷歌浏览器自动下载”""
# 创建谷歌浏览器配置对象
chromeOptions = webdriver.ChromeOptions()
# 将下载文件保存在E盘的iDownload目录
# 如果该文件不存在,自动创建
prefs = {“download.default_directory”:“E:\iDownload”}
# 将自定义设置添加到Chrome配置对象实例中
chromeOptions.add_experimental_option(‘prefs’,prefs)
# 启动带有自定义设置的Chrome浏览器
self.dr = webdriver.Chrome(chrome_options=chromeOptions)
def tearDown(self) -> None:
self.dr.quit()
def test_download(self):
# 下载谷歌浏览器
self.dr.get('http://tj123.mydown.com/shadu/mgr3/f336.shtml?sfrom=166&keyID=37659')
self.dr.implicitly_wait(20)
self.dr.find_element_by_link_text('安全下载').click()
time.sleep(200)
if name == ‘main’:
unittest.main()