robotframework+selenium2library之上传本地文件

来源:互联网 发布:js下拉刷新原理 编辑:程序博客网 时间:2024/06/08 10:59

针对将本地的文件上传到测试系统,selenium2library提供了一个关键词

choose file

官方给定的解释如下:

Source:
Selenium2Library <test library>
Arguments:
[ locator | file_path ]
Inputs the `file_path` into file input field found by `identifier`.
This keyword is most often used to input files into upload forms. The file specified with `file_path` must be available on the same host where the Selenium Server is running.
Example:
Choose File my_upload_field  /home/user/files/trades.csv

一开始以为进入到上传页面,点击浏览,再使用choose file,结果发现,这个函数包含了 点击浏览--选中文件  那么点击浏览就是多余的操作了 


在该页面,就只需要执行choose  就可以将图片选中,执行的具体命令为:

choose file    xpath=//div[@class='pd6 dot fcb']/span/input    C:\\Documents and Settings\\zhouxuan\\My Documents\\My Pictures\\bug5.png

其中xpath为选中浏览图标的路径,而 C:\\Documents and Settings\\zhouxuan\\My Documents\\My Pictures\\bug5.png(此处的\\为转义用,当只用\时会出现错误)则为需要上传的图片的路径。

该操作执行完毕后,则会显示为:


图片已经顺利加载进来了,后续的操作就很简单了。


ps:

一开始点击上传图片的按键的时候,一直失败,各种调试和转换路径,但是都失败,后来换到同事的环境下执行,一切OK,查看火狐的版本,我的是35.0版本,他的是22.0.后来我也火狐浏览器的版本降低到22.0.脚本运行正常了。想想之前有时候在火狐下运行会导致浏览器不响应,也可能和浏览器相关。今天应该解决了。




1 0
原创粉丝点击