您的位置:首页 > 其它

selenium结合autoit3实现文件上传及下载

2016-04-15 22:51 791 查看
Au3脚本是AutoIt3 Windows自动安装脚本语言。AutoIt 是一种自动控制工具。它可以被用来自动完成任何基于 Windows 或 DOS 的简单任务。下面将结合selenium来实现文件的上传和下载。

1、首先下载au3(百度搜索autoIt3直接访问官网即可)

2、au3定位文件上传窗口



3、编写au3脚本并compile成对应的*.exe可执行文件以便调用

;ControlFocus("title","text",controlID) Edit1=Edit instance 1
ControlFocus("打开", "","Edit1")

;Wait 10 seconds for the Upload window to appear
WinWait("[CLASS:#32770]","",10)

Sleep(2000)

;Set the File name text on the Edit field
ControlSetText("打开", "", "Edit1", "E:\test\upload.png")

Sleep(2000)

;Click on the Open button
ControlClick("打开", "","Button1");

4、结合selenium实现文件的上传

try {
Runtime.getRuntime().exec("E:\\test\\upload.exe");
} catch (IOException e) {
System.err.println("调用autoit3失败!");
}

5、同理,下载

;ControlFocus("title","text",controlID) Edit1=Edit instance 1
ControlFocus("另存为", "","Edit1")
; 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 autoit3 windows