1、selenium3 实现文件下载

from selenium import webdriver
import os

options = webdriver.ChromeOptions()
prefs = {'profile.default_content_settings.popups': 0,  #设置为禁止弹出下载窗口
         'download.default_directory': os.getcwd()  #设置为文件下载路径
         }
options.add_experimental_option('prefs', prefs)

driver = webdriver.Chrome(chrome_options=options)
driver.get("http://pypi.Python.org/pypi/selenium")  #文件下载地址
driver.find_element_by_link_text("Download files").click()  #切换到下载页面
driver.find_element_by_partial_link_text("selenium-3.141.0.tar.gz").click() #单击下载文件

 

2、selenium3 实现文件上传

目录结构

selenium实现文件的上传与下载

生成 upfile.html(用于演示上传功能)

<html>
    <head>
        <meta http-equiv="content-type" content="text/html;charset=utf-8" />
        <title>upload_file</title>
        <link href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" />
    </head>
    <body>
        <div class="row-fluid">
            <div class="span6 well">
                <h3>upload_file</h3>
                <input type="file" name="file" />
            </div>
        </div>
    </body>
    <script src="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.js"></script>
</html>
View Code

相关文章:

  • 2022-12-23
  • 2021-11-13
  • 2021-12-15
  • 2021-07-10
  • 2021-07-11
  • 2022-02-04
  • 2022-12-23
  • 2021-08-31
猜你喜欢
  • 2021-12-22
  • 2022-12-23
  • 2022-02-11
  • 2022-02-07
  • 2021-12-02
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案