selenium —— Chrome浏览器文件下载
上一篇 /
下一篇 2017-09-20 14:37:50
/ 个人分类:Selenium
最近一直在看虫师的《selenium2 +
Python自动化测试实战》,看到文件下载章节中只介绍了FireFox浏览器下执行文件下载的实例。我个人非常喜欢使用Chrome浏览器,在
百度上搜索了众多资料,最后将自己实现的代码
记录下来,以备他用。
#!/usr/bin/env python
#-- coding:utf-8 --
fromseleniumimportwebdriver
fromtimeimportsleep
chromepath ='D:\Program Files\Python3.5.2\chromedriver.exe'
options = webdriver.ChromeOptions()
prefs = {'profile.default_content_settings.popups':0,
'download.default_directory':'f:\\'}
options.add_experimental_option('prefs',prefs)
driver = webdriver.Chrome(executable_path= chromepath,chrome_options= options)
driver.get('http://vdisk.weibo.com/s/sOaJBfdTbKYkV')
driver.find_element_by_xpath('//*[@id="download_big_btn"]').click()
sleep(30)
driver.quit()
收藏
举报
TAG: