selenium和AutoIt工具辅助下载和上传
上传
根据AutoIt Windows Info 所识别到的控件信息打开SciTE Script Editor编辑器,编写脚本。

;ControlFocus("title","text",controlID) Edit1=Edit instance 1
ControlFocus("选择要加载的文件", "","Edit1")
; Wait 10 seconds for the Upload window to appear
WinWait("[CLASS:#32770]","",10)
; Set the File name text on the Edit field
//要上传的文件
ControlSetText("选择要加载的文件", "", "Edit1", "D:\\upload_file.txt")
Sleep(2000)
; Click on the Open button
ControlClick("选择要加载的文件", "","Button1");

ControlFocus()方法用于识别Window窗口。WinWait()设置10秒钟用于等待窗口的显示,其用法与WebDriver 所提供的implicitly_wait()类似。ControlSetText()用于向“文件名”输入框内输入本地文件的路径。这里的Sleep()方法与Python中time模块提供的Sleep()方法用法一样,不过它是以毫秒为单位,Sleep(2000)表示固定休眠2000毫秒。ControlClick()用于点击上传窗口中的“打开”按钮。
AutoIt的脚本已经写好了,可以通过菜单栏“Tools”-->“Go” (或按键盘F5)来运行一个脚本吧!注意在运行时上传窗口当前处于打开状态。
3、脚本运行正常,将其保存为upfile.au3,这里保存的脚本可以通过Run Script 工具将其打开运行,但我们的目的是希望这个脚本被Python程序调用,那么就需要将其生成exe程序。打开Compile Script to.exe工具,将其生成为exe可执行文件。如图4.16,

图4.16 Compile Script to.exe生成exe程序
点击“Browse”选择upfile.au3文件,点击“Convert”按钮将其生成为upfile.exe程序。
4、下面就是通过自动化测试脚本调用upfile.exe程序实现上传了。

#coding=utf-8
from selenium import webdriver
import os driver = webdriver.Firefox() #打开上传功能页面
file_path = 'file:///' + os.path.abspath('upfile.html')
driver.get(file_path) #点击打开上传窗口
driver.find_element_by_name("file").click()
#调用upfile.exe上传程序
os.system("D:\\upfile.exe") driver.quit()

; Wait 10 seconds for the Upload window to appear
WinWait("[CLASS:#32770]","",10)
; Set input focus to the edit control of Upload window using the handle returned by WinWait
ControlFocus("另存为","","Edit1")
Sleep(2000)
; Set the File name text on the Edit field
//下载的保存路径
ControlSetText("另存为", "", "Edit1", "d:\autoit-v3-setup")
Sleep(2000)
; Click on the Open button
ControlClick("另存为", "","Button1");
ControlFocus("另存为", "","Edit1");ControlFocus("title","text",controlID) Edit1=Edit instance 1
; Wait 10 seconds for the Upload window to appear
WinWait("[CLASS:#32770]","",10)
; Set input focus to the edit control of Upload window using the handle returned by WinWait
ControlFocus("另存为","","Edit1")
Sleep(2000)
; Set the File name text on the Edit field
ControlSetText("另存为", "", "Edit1", "d:\autoit-v3-setup")
Sleep(2000)
; Click on the Open button
ControlClick("另存为", "","Button1");
selenium和AutoIt工具辅助下载和上传的更多相关文章
- 重新想象 Windows 8 Store Apps (66) - 后台任务: 下载和上传
[源码下载] 重新想象 Windows 8 Store Apps (66) - 后台任务: 下载和上传 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 后台任务 后台 ...
- 重新想象 Windows 8.1 Store Apps (91) - 后台任务的新特性: 下载和上传的新特性, 程序启动前预下载网络资源, 后台任务的其它新特性
[源码下载] 重新想象 Windows 8.1 Store Apps (91) - 后台任务的新特性: 下载和上传的新特性, 程序启动前预下载网络资源, 后台任务的其它新特性 作者:webabcd 介 ...
- github下载和上传项目
git下载和上传项目 下载: git clone +地址 上传: 1.git init 在当前项目的目录中生成本地的git管理(多一个.git文件夹,为隐藏文件) 2.git add .(注意最后面有 ...
- python+selenium下载和上传文件
操作浏览器上传文件,先看代码 1 """ 2 * send_keys() 指定文件上传路径. 3 """ 4 from selenium i ...
- 在XShell中使用sz和rz命令下载和上传文件
借助XShell,使用linux命令sz可以很方便的将服务器上的文件下载到本地,使用rz命令则是把本地文件上传到服务器 工具/原料 XShell CentOS 6.5 使用sz下载文件 1 输 ...
- 使用MFC提供的Http类下载和上传文件
1.下载文件 Download(const CString& strFileURLInServer, //待下载文件的URL const CString & strFileLocalF ...
- 2.4 利用FTP服务器下载和上传目录
利用FTP服务器下载目录 import os,sys from ftplib import FTP from mimetypes import guess_type nonpassive = Fals ...
- 2.3 利用FTP服务器下载和上传文件
二.利用FTP服务器的下载文件 from ftplib import FTP from os.path import exists def getfile(file,site,dir,user=(), ...
- 从Nexus私服下载和上传资源(一)
从私服中下载资源 首先要明确将资源下载到哪里 找到maven 配置文件settings.xml 文件,添加如下配置:1.添加镜像配置:将所有访问外网仓库的请求指向私服: <mirror> ...
随机推荐
- centos 7下配置阿里yum源
1.打开centos的yum文件夹 cd /etc/yum.repos.d/ 2.用wget下载repo文件 wget http://mirrors.aliyun.com/repo/Centos-7. ...
- 原生表格table
1).table{ width: 100%;//让表格里面的内容充满整个区域 border-collapse:collapse; 去掉html表格之table间的空隙} ...
- github配置ssh及多ssh key问题处理
一.生成ssh公私钥 用ssh-keygen生成公私钥. $ssh-keygen -t rsa -C "你的邮箱" -f ~/.ssh/id_rsa_mult 在~/./ssh目录 ...
- keeplived+lvs(主从热备+负载均衡)
本次实验基于DR负载均衡模式(直接路由),设置一个VIP(Virtual IP)为192.168.1.225,用户只需要访问这个IP地址即可获得网页服务.其中,负载均衡主机为192.168.1.221 ...
- 攻防世界web之PHP2
题目 御剑扫描无果,源码也无发现 但是在url后面添加index.phps发现代码泄露 右击查看源码 审计代码 首先不能admin等于get传过来的值 又要使admin等于get传值 在get传值之前 ...
- Spring Boot 自定义Intercepter
在 SpringBoot2.X 中 ,WebMvcConfigurerAdapter 被deprecated , 更好的做法是 implements WebMvcConfigurer 一.自定义拦截器 ...
- verilog语法标准
initial 中语句超过一需要添加begin和end: 1995 2001 介绍了当用逗号分隔敏感列表更方便构成事件控制表达式的选择条件: 2005 2001/2005语法标准,没有类型定义的任何标 ...
- LG2375/LOJ2246 「NOI2014」动物园 KMP改造
问题描述 LG2375 LOJ2246 题解 看了题解,需要回看,需要继续通过本题深入理解KMP. 为了将 \(\mathrm{KMP}\) 和只插入了一个模式串的\(\mathrm{AC}\)自动机 ...
- github 入门教程之 github 访问速度太慢怎么办
github 是全世界最流行的开源项目托管平台,其代表的开源文化从根本上改变了软件开发的方式. 基本上所有的需求都能从 github 上或多或少找到现成的实现方案,再也不用重头开始造轮子而是自定义轮子 ...
- Python 对象比较(is & ==)
Python 对象有 3 要素 id type value id 对象在内存中的地址 可以通过 id() 获取 比较 只有同一个对象 id 才会相同 id 通过 is 比较 示例: a = list( ...