Robot Framework之Selenium2Library库的关键字

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/chuhe163/article/details/102549417


1、Open Browser打开浏览器

  • 打开URL地址,一定要安装浏览器相对应的驱动
  • 如chrome 的驱动:chromedriver.exe 。
  • 浏览器默认为空时启动FireFox。
Open Browser    https://www.baidu.com/    Chrome
浏览器 对应指令
Firefox firefox, ff
Google Chrome googlechrome, chrome, gc
Headless Firefox headlessfirefox
Headless Chrome headlesschrome
Internet Explorer internetexplorer, ie
Edge edge
Safari safari
Opera opera
Android android
Iphone iphone
PhantomJS phantomjs
HTMLUnit htmlunit
HTMLUnit with Javascript htmlunitwithjs

2、Close Browser关闭浏览

  • 关闭当前浏览器
Close Browser
  • 关闭所有打开的浏览器和浏览器缓存重置。
Close All Browsers

3、Maximize Browser Window浏览器窗口最大化

  • 浏览器窗口最大化
Maximize Browser Window

4、Set Window Size设置浏览器宽、高

  • 以像素为单位,宽800,高600
Set Window Size    800    600

5、Input Text文本输入

Input Text    id=kw    自动化测试

6、Click Element点击元素

Click Element    id=su

7、Click Button点击按钮

Click Button    id=su

8、注释

  • 方法1
Comment     注释说明
  • 方法2
  • Robot framework框架是基于python语言开发的,所以提供了python语言的注释“#”方式
#注释说明

9、Sleep休眠

  • 休眠5秒
Sleep 5

10、Wait Until Page Contains Element等待元素出现在当前页面

  • 定位元素,最长等待10秒,超时提示“未定位到元素”
Wait Until Page Contains Element    id=kw    10    未定位到元素

11、Get Title获取title

  • 获取窗口title并赋值给变量${title}
${title}    Get TiTle

12、Get Text

  • 获取文本属性
  • Returns the text value of the element identified by locator.
${submit}    Get Text    id=su

13、Get Value

  • Returns the value attribute of the element identified by locator.
${submit}    Get Value    id=su

14、Get Element Attribute

  • Returns the value of attribute from the element locator.
  • 获取id=kw 元素的name属性
${name}    Get Element Attribute    id=kw    name

15、cookie处理

  • 获得当前浏览器的所有cookie
get cookies
  • 获得key=Key_name的cookie值
get cookie value    Key_name
  • 删除key=Key_name的cookie值
delete cookie    Key_name
  • 删除当前浏览器的所有cookie
delete all cookies
  • 添加cookie
add cookie    Key_name    Value_name

16、获得浏览器窗口宽、高

  • 获得浏览浏览器窗口宽、高,分别赋值给${width} 和${height}
${width}    ${height}    get window size

17、断言

Open Browser    https://www.baidu.com/    Chrome
${title}    Get Title
should contain    ${title}    百度一下,你就知道

18、表单嵌套

  • 进入表单
Select Frame   Xpath=//* [@]
  • 退出表单
Unselect Frame

猜你喜欢

转载自blog.csdn.net/chuhe163/article/details/102549417