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 实现文件上传
目录结构
生成 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>