1、将下面代码保存为 upload_file.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>
2、用浏览器打开后,应该是这样
3、打开 SciTE Script Editor 脚本编辑器,编写脚本(上篇博客有介绍如何识别windows控件,AutoIt基础语法 !!)
;等待打开窗口出现 WinWaitActive("打开","",10) ;聚焦到需要上传的元素 ;ControlFocus("[Class:#32770]", "", "Edit1") ;安全的写法 ControlFocus("打开", "","Edit1") ;上传文件 ControlSetText("打开", "", "Edit1", "C:Userscai-xiaobaiDesktopupload_file.txt") Sleep(2000) ;点击打开按钮 ControlClick("打开", "","Button1");
4、使用 Compile Script to .exe 编译脚本
5、将编译后的脚本放入robotframework中执行
*** Settings *** Library AutoItLibrary Library SeleniumLibrary *** Test Cases *** demo1 open browser file:///C:/Users/cai-xiaobai/Desktop/uploadfile.html gc #gc指代谷歌 Maximize Browser Window click element xpath=//*[@name="file"] sleep 5 Evaluate os.system("d:\upfile.exe") #执行 AutoIt 脚本 close browser
6、最后执行脚本就ok了~~~~