上一小节介绍介绍了 SeleniumLibrary 的常用关键字,这一节来举两个例子。

百度搜索实例


*** Settings ***Documentation ????Simple example using SeleniumLibrary.Library ??????????SeleniumLibrary*** Test Cases ***Baidu search case ???Open Browser ???https://www.baidu.com ???chrome ???Input text ???id:kw ???selenium ???click button ???id:su ???Evaluate ???time.sleep(2) ???time ???${title} ???Get Title ???should contain ????${title} ????selenium_百度搜索 ???close Browser

其中 sleep 为 Python 所提供的休眠方法。Get Title 获得搜索之后的页面标题,通过 should contain 关键字来断言标题是否正确。

126 邮箱登录实例


*** Settings ***Documentation ????Simple example using SeleniumLibrary.Library ??????????SeleniumLibrary*** Test Cases ***Mial login case ???Open Browser ???http://www.126.com ???chrome ???Evaluate ???time.sleep(3) ???time ???Select Frame ???xpath=//*[@id="x-URS-iframe"] ???Input text ???name:email ???username ???Input text ???name:password ???123456 ???click element ??id:dologin ???Unselect Frame ???close Browser

这里主要使用了 Select Frame 关键字切换表单,登录按钮要用 click element 关键字。