robot_framework + selenium + 上传本地文件+win7 32位

1、下载与安装AutoIt v3  地址链接:http://pan.baidu.com/s/1hqsDFBA,我自己是32位的系统,用这个运行可以

2、安装完成后,如下图所示

3、 AutoIt Windows Info 用于帮助我们识 Windows 控件信息。
  Compile Script to.exe 用于将 AutoIt 生成 exe 执行文件。
  Run Script 用于执行 AutoIt 脚本。
  SciTE Script Editor 用于编写 AutoIt 脚本

4、上传一个html备用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>

5、 通过浏览器打开upfile.html,效果如下图所示(建议用火狐打开)

6、 此时打开AutoIt Window Info,鼠标点击 Finder Tool,鼠标将变成一个小风扇形状的图标,按住鼠标左键拖动到需要识别的控件上。

7、首先需要识别的是文本框。

8、识别文本框后,就要在该文本框中输入文件路径,之后就是点击【打开】按钮,所以嘞,待会还要按照步骤7定位下按钮的位置。按照这个思路打开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)
ControlClick("文件上传", "", "Button1")
; Click on the Open button

9、 将上面的文件保存成11.au3文件

10、将11.au3转化成exe文件,因为exe文件可以直接执行

11、 打开Compile Script to .exe,我是32位的,直接如下图所示就可以了

12、 打开ride,直接上代码

open browser file:///C:/Users/Administrator/Desktop/11.html
click element xpath=/html/body/div/div/input

sleep 2
evaluate os.system('C:/Users/Administrator/Desktop/11.exe') os

13、直接执行,报告pass了。界面上显示有添加本地文件,但是不知道为什么有这样的错误,欢迎大家拍砖

原文地址:https://www.cnblogs.com/caixiaohong/p/4930921.html