robotframework 文件上传

pycharm的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>

在pycharm执行upfile.html,可能会又chrome浏览器打不开的问题。pycharm|File | Settings | Tools | Web Browsers and Preview ,name为chrome的path选中chrome的安装路径即可解决。

autoIt v3->sciTE script Editor 新建upfile.au3文档:

#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:\upfile.txt")
Sleep(2000)
#Click on the Open button
ControlClick("打开", "","Button1")

 .au3中文会显示乱码,需要在Options->open sciTE user options 写入以下代码:会解决中文乱码

# Japanese input code page 932 and ShiftJIS character set 128
#code.page=932
#character.set=128
# Unicode
#~ code.page=65001
code.page=936
#character.set=204
#command.discover.properties=python /home/user/FileDetect.py "$(FilePath)"
# Required for Unicode to work on GTK+:
#LC_CTYPE=en_US.UTF-8
if PLAT_WIN
    output.code.page=936
if PLAT_GTK
    output.code.page=936
if PLAT_MAC
    output.code.page=936
#缩进字符数
indent.size=4
#缩进使用tab键
use.tabs=1
#缩进,就是自动保持前一行的缩进
#indent.auto=1
#智能缩进,和上面的区别就是有反缩进
indent.automatic=1
#代码缩进,比如大括号回车自动缩进
indent.opening=1
#代码反缩进,同上
indent.closing=1
#tab键缩进
#tab.indents=0
#自动换行开关,写代码一般不要打开自动换行
#wrap=1
#换行的风格,没用过
#wrap.style=2
#输出窗口自动换行
#output.wrap=1
#自动换行处的标记符
wrap.visual.flags=3
#代码折叠开关,建议打开
fold=1
#折叠指示,建议打开
fold.compact=1
#折叠代码样式1\2\3,2比较好看
fold.symbols=2
#代码折叠区的宽度
fold.margin.width=16
#代码注释折叠
fold.comment=1
#折叠预处理
fold.preprocessor=1
#鼠标到达文件末尾行后滚动条可继续下移
end.at.last.line=0
#显示行号
line.margin.visible=1
#行号显示的位数,3+表示默认3位数,不够再加
line.margin.width=3+
#行号缩进的宽度,最好不缩进
margin.width=0
#长行指示
edge.column=200
edge.mode=0
edge.colour=#F9F9F9

通过tools->go或者F5,执行upfile.au3之前,需要先执行upfile.html并点击【选中文件】按钮,弹出”打开“框。

以上页面打开后,再执行upfile.au3代码。浏览器会自动选中upfile.au3代码中需要上传的upfile.txt文档。

robot的代码,点击【选中文件】用click element \click button不行。得用press keys

open browser	file:///C:/Users/Administrator/PycharmProjects/pythonProjectYu/upfile.html	chrome
Maximize Browser Window		
sleep	5	
press keys	xpath=/html/body/div/div/input	\\32
sleep	5	
log	测试	
evaluate	os.system("D:/Program Files (x86)/AutoIt3/SciTE/upfile.exe")	#执行autoIt脚本
sleep	5	
log	结束	

evaluate    os.system("D:/Program Files (x86)/AutoIt3/SciTE/upfile.exe")    #执行autoIt脚本
做到这一步没法成功。试过了把autoit 装到d盘,用管理员身份运行ride.都不行。唉

解决了,os.system双引号外再加一个单引号,或者把.exe文件直接放到没有空格的路径下都可以。我也不清楚为什么要这么操作,可能是有空格会当作多个参数传递吧,搜索到有类似解决办法的说是因为路径中间有空格,参考【ErrorStdOut在AutoIt的 - VoidCC

open browser	file:///C:/Users/Administrator/PycharmProjects/pythonProjectYu/upfile.html
Maximize Browser Window	
sleep	5
press keys	xpath=/html/body/div/div/input
sleep	5
log	测试
evaluate	os.system('"D:/Program Files (x86)/AutoIt3/SciTE/upfile.exe"')
sleep	5
log	结束

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值