RobotFramework操作API

x33g5p2x  于2021-11-02 转载在 其他  
字(1.0k)|赞(0)|评价(0)|浏览(304)

一:RobotFramework之UI自动化测试环境

1:通过pip安装扩展库

pip install robotframework-seleniumlibrary

2:下载谷歌游览器和对应驱动

http://chromedriver.storage.googleapis.com/index.html

找到和自己谷歌版本相匹配的驱动

选择自己的系统去下载

3:将游览器驱动放在python的目录下

比如:我的python安装在E:\python目录中(chromedriver.exe放入对应的python 目录下)

4:导入SeleniumLibrary扩展库

二:API操作

1:打开游览器(访问网站)

Open Browser   http://www.baidu.com   chrome

2:设置睡眠时间

sleep 时间(秒)

3:设置隐式等待时间

Set Browser Implicit Wait 时间(秒)

4:窗口最大化

Maximize Browser Window

5:设置窗口位置

Set Window Position 30  50

6:返回上一步

Go Back

7:跳转

Go To   http://www.baidu.com

8:刷新

Reload Page

图片展示

三:RF元素定位

selenium中八大定位方式:

id,name,xpath,css,link_text,partial_link_text,class_name,tag_name

前提:元素必须是唯一的

回顾
xpath

1:通过绝对路径定位元素:  (不推荐使用)
2:通过相对路径定位元素:xpath=//form/span/input 
3:通过元素属性定位元素:xpath=//input[@autocomplete="off" and @class="s_ipt"] 
4:通过部分元素属性定位:xpath=//input[contains(@autocomplete="of")] 5:通过元素文本定位元素:xpath=//a[text()="新闻"]

CSS

1:通过id进行定位:#ID 
2:通过class定位:.class 
3:通过元素属性定位:css=input[autocomplete="off"] 
4:通过部分属性定位:css=input[autocomplete*="of"] 
5:通过子元素定位:css=div#s-top-left a:nth-child(3)

图片展示

相关文章

微信公众号

最新文章

更多