zoukankan      html  css  js  c++  java
  • python3.6+selenium使用chrome浏览器自动将文件下载到指定路径

    通过设置Chrome属性,实现脚本自动下载网页上的文件,并保存到指定路径下,以下是实例完成代码,请参考:
    import unittest
    from selenium import webdriver
    import time

    class MyTestCase(unittest.TestCase):
    def setUp(self):
    self.driver=webdriver.Chrome(executable_path=’/python/driver/chromedriver’)
    #创建Chrome浏览器配置对象
    chromeOptions=webdriver.ChromeOptions()
    #设定下载文件的保存目录为D盘的D:\downloadFile
    #如果该目录不存在则直接创建
    prefs={“download.default_directory”:“D:\downloadFile”}
    #将自定义设置添加到chrome配置对象实例中
    chromeOptions.add_experimental_option(“prefs”,prefs)
    #启动带有自定义设置的chrome浏览器
    self.driver=webdriver.Chrome(executable_path=’/python/driver/chromedriver’,chrome_options=chromeOptions)
    def test_downloadFile(self):
    url=“http://pypi.python.org/pypi/selenium”
    self.driver.get(url)
    time.sleep(5)
    #定位下载文件链接页面元素,并单击进行下载
    self.driver.find_element_by_partial_link_text(“selenium-server-standalone-3.141.0.jar”).click()
    time.sleep(100)

    if name == ‘main’:
    unittest.main()


    ————————————————
    版权声明:本文为CSDN博主「Chris~Ma」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/Marry_Ma/article/details/96424482

  • 相关阅读:
    css选择器(常规选择器,伪类选择器,伪元素选择器,根元素选择器)
    css文件引人的三种方式
    《软件测试》阅读笔记
    测试风险管理
    软件缺陷分析
    软件文档
    软件缺陷分析方法
    软件缺陷分析方法:ODC
    [转载]web测试方法总结
    测试报告笔记
  • 原文地址:https://www.cnblogs.com/javalinux/p/14804401.html
Copyright © 2011-2022 走看看