本篇文章给大家谈谈RobotFrameworkSelenium2关键字,以及robotframework关键字编写的知识点,同时本文还将给你拓展Appium+RobotFramework常用关键字、l
本篇文章给大家谈谈RobotFramework Selenium2 关键字,以及robotframework关键字编写的知识点,同时本文还将给你拓展Appium+RobotFramework常用关键字、linux上配置robotframework环境及selenium2library、mac下使用robotframework-selenium2library做web自动化、Roboframework - Selenium - 查找所有包含特定文本的 HREF等相关知识,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:- RobotFramework Selenium2 关键字(robotframework关键字编写)
- Appium+RobotFramework常用关键字
- linux上配置robotframework环境及selenium2library
- mac下使用robotframework-selenium2library做web自动化
- Roboframework - Selenium - 查找所有包含特定文本的 HREF
RobotFramework Selenium2 关键字(robotframework关键字编写)
RobotFramework Selenium2 关键字
*** Settings ***
Library Selenium2Library
*** Keywords ***
Checkbox应该不被选择
[Arguments] ${locator}
Checkbox Should Not Be Selected ${locator}
Frame应该包含文本
[Arguments] ${locator} ${text} ${loglevel}=INFO
Frame Should Contain ${locator} ${text} ${loglevel}
List应该无选项
[Arguments] ${locator}
List Should Have No Selections ${locator}
List选项应该是
[Arguments] ${locator} @{items}
List Selection Should Be ${locator} @{items}
Radio按钮不应该被选择
[Arguments] ${group_name}
Radio Button Should Not Be Selected ${group_name}
Radio按钮应该被设置成
[Arguments] ${group_name} ${value}
Radio Button Should Be Set To ${group_name} ${value}
Url应该包含
[Arguments] ${expected}
Location Should Contain ${expected}
Xpath应该匹配X次
[Arguments] ${xpath} ${expected_xpath_count} ${msg}= ${loglevel}=INFO
Xpath Should Match X Times ${xpath} ${expected_xpath_count} ${msg} ${loglevel}
checkbox应该被选择
[Arguments] ${locator}
checkbox should be selected ${locator}
url应该是
[Arguments] ${url}
Location Should Be ${url}
下次确认选择取消
Choose Cancel On Next Confirmation
下次确认选择确定
Choose Ok On Next Confirmation
从List中取消选项
[Arguments] ${locator} @{items}
Unselect From List ${locator} @{items}
从List选择选项
[Arguments] ${locator} @{items}
Select From List ${locator} @{items}
偏移拖拽
[Arguments] ${source} ${xoffset} ${yoffset}
Drag And Drop By Offset ${source} ${xoffset} ${yoffset}
元素应该不包含文本
[Arguments] ${locator} ${expected} ${msg}=
Element Should Not Contain ${locator} ${expected} ${msg}
元素应该不可用
[Arguments] ${locator}
Element Should Be Disabled ${locator}
元素应该不可见
[Arguments] ${locator} ${msg}=
Element Should Not Be Visible ${locator} ${msg}
元素应该包含文本
[Arguments] ${locator} ${text}
Element Should Contain ${locator} ${text}
元素应该匹配x次
[Arguments] ${locator} ${count} ${msg}= ${loglevel}=INFO
Locator Should Match X Times ${locator} ${count} ${msg} ${loglevel}
元素应该可用
[Arguments] ${locator}
Element Should Be Enabled ${locator}
元素应该可见
[Arguments] ${locator}
Element Should Be Visible ${locator}
元素文本应该是
[Arguments] ${locator} ${expected} ${msg}=
Element Text Should Be ${locator} ${expected} ${msg}
全选List元素
[Arguments] ${locator}
Select All From List ${locator}
关闭所有浏览器
Close All Browsers
关闭浏览器
Close Browser
关闭窗口
Close Window
切换浏览器
[Arguments] ${index}
Switch Browser ${index}
创建Webdriver
[Arguments] ${driver_name} ${alias}= ${kwargs}={}
Create Webdriver ${driver_name} ${alias} ${kwargs}
删除Cookie
[Arguments] ${name}
Delete Cookie ${name}
删除所有Cookie
Delete All Cookies
删除本地策略
[Arguments] ${strategy_name}
Remove Location Strategy ${strategy_name}
刷新页面
Reload Page
双击元素
[Arguments] ${locator}
Double Click Element ${locator}
取消选择Checkbox
[Arguments] ${locator}
Unselect Checkbox ${locator}
取消选择Frame
Unselect Frame
回退
Go Back
在图片上按下鼠标左键
[Arguments] ${locator}
Mouse Down On Image ${locator}
在连接上按下鼠标左键
[Arguments] ${locator}
Mouse Down On Link ${locator}
应该出现警告弹窗
[Arguments] ${text}=
Alert Should Be Present ${text}
当前Frame不应该包含
[Arguments] ${text} ${loglvl}=INFO
Current Frame Should Not Contain ${text} ${loglvl}
当前Frame包含
[Arguments] ${text} ${loglevel}=INFO
Current Frame Contains ${text} ${loglevel}
截屏
[Arguments] @{filename}
Capture Page Screenshot @{filename}
打开浏览器
[Arguments] ${url} ${browser}=chrome @{args}
Open Browser ${url} ${browser} @{args}
打开菜单
[Arguments] ${locator}
Open Context Menu ${locator}
执行js
[Arguments] ${code}
Execute Javascript ${code}
执行异步js
[Arguments] ${code}
Execute Async Javascript ${code}
拖拽元素
[Arguments] ${source} ${target}
Drag And Drop ${source} ${target}
按下鼠标左键
[Arguments] ${locator}
Mouse Down ${locator}
按键
[Arguments] ${locator} ${key}
[Documentation] 按键 \ \ text_field \ \ q
...
... 按键 \ \ login_button \ \\13 \ \ #ASCII Code for enter Key
Press Key ${locator} ${key}
提交表单
[Arguments] ${locator}=
Submit Form ${locator}
文本区值应该是
[Arguments] ${locator} ${expected} ${msg}=
Textarea Value Should Be ${locator} ${expected} ${msg}
文本区应该包含
[Arguments] ${locator} ${expected} ${msg}=
Textarea Should Contain ${locator} ${expected} ${msg}
文本框值应该是
[Arguments] ${locator} ${expected} ${msg}=
Textfield Value Should Be ${locator} ${expected} ${msg}
文本框应该包含
[Arguments] ${locator} ${expected} ${msg}=
Textfield Should Contain ${locator} ${expected} ${msg}
最大化
Maximize Browser Window
标题应该是
[Arguments] ${title}
Title Should Be ${title}
根据Index从List中取消选项
[Arguments] ${locator} @{indexes}
Unselect From List By Index ${locator} @{indexes}
根据Index从List选择
[Arguments] ${locator} @{indexes}
Select From List By Index ${locator} @{indexes}
根据Label从List中取消选项
[Arguments] ${locator} @{Labels}
Unselect From List By Label ${locator} @{Labels}
根据Label从List选择
[Arguments] ${locator} @{labels}
Select From List By Label ${locator} @{labels}
根据Value从List中取消选项
[Arguments] ${locator} @{values}
Unselect From List By Value ${locator} @{values}
根据Value从List选择
[Arguments] ${locator} @{values}
Select From List By Value ${locator} @{values}
根据值选择列表元素
[Arguments] ${locator} ${value}
Select From List By Value ${locator} ${value}
模拟
[Arguments] ${locator} ${event}
Simulate ${locator} ${event}
注册失败后运行的关键字
[Arguments] ${kwd}
Register Keyword To Run On Failure ${kwd}
添加cookie
[Arguments] ${name} ${value} ${path}= ${domain}= ${secure}= ${expiry}=
添加本地策略
[Arguments] ${strategy_name} ${strategy_keyword} ${persist}=False
Add Location Strategy ${strategy_name} ${strategy_keyword} ${persist}
清除元素文本
[Arguments] ${locator}
Clear Element Text ${locator}
点击元素
[Arguments] ${path}
Click Element ${path}
点击元素坐标
[Arguments] ${locator} ${xoffset} ${yoffset}
Click Element At Coordinates ${locator} ${xoffset} ${yoffset}
点击图片
[Arguments] ${locator}
Click Image ${locator}
点击按钮
[Arguments] ${path}
Click Button ${path}
点击链接
[Arguments] ${locator}
Click Link ${locator}
睡眠
[Arguments] ${time}
Sleep ${time}
确认
Confirm Action
窗口列表
@{list} List Windows
[Return] @{list}
等待元素不包含文本
[Arguments] ${locator} ${text} ${timeout}= ${error}=
Wait Until Element Does Not Contain ${locator} ${text} ${timeout} ${error}
等待元素不可见
[Arguments] ${locator} ${timeout}= ${error}=
Wait Until Element Is Not Visible ${locator} ${timeout} ${error}
等待元素包含文本
[Arguments] ${locator} ${text} ${timeout}= ${error}=
Wait Until Element Contains ${locator} ${text} ${timeout} ${error}
等待元素可用
[Arguments] ${locator} ${timeout}= ${error}=
Wait Until Element Is Enabled ${locator} ${timeout} ${error}
等待元素可见
[Arguments] ${locator} ${timeout}=30
Wait Until Element Is Visible ${locator} ${timeout}
等待执行成功
[Arguments] ${timeout} ${retry} ${keyword} @{args}
Wait Until Keyword Succeeds ${timeout} minutes ${retry} sec ${keyword} @{args}
等待条件成立
[Arguments] ${condition} ${timeout}= ${error}=
Wait For Condition ${condition} ${timeout} ${error}
等待页面不包含元素
[Arguments] ${locator} ${timeout}= ${error}=
Wait Until Page Does Not Contain Element ${locator} ${timeout} ${error}
等待页面包含元素
[Arguments] ${locator} ${timeout}= ${error}=
Wait Until Page Contains Element ${locator} ${timeout} ${error}
等待页面包含文本
[Arguments] ${text} ${timeout}= ${error}=
Wait Until Page Contains ${text} ${timeout} ${error}
给元素分配ID
[Arguments] ${locator} ${id}
Assign Id To Element ${locator} ${id}
获取Cookie值
[Arguments] ${name}
${value} Get Cookie Value ${name}
[Return] ${value}
获取List元素
[Arguments] ${locator}
@{items} Get List Items ${locator}
获取List多个选定值
[Arguments] ${locator}
@{values} Get Selected List Values ${locator}
[Return] @{values}
获取List多个选定标签
[Arguments] ${locator}
@{labels} Get Selected List Labels ${locator}
[Return] @{labels}
获取List选定值
[Arguments] ${locator}
${value} Get Selected List Value ${locator}
[Return] ${value}
获取List选定标签
[Arguments] ${locator}
${label} Get Selected List Label ${locator}
[Return] ${label}
获取Selenium等待时间
${sec} Get Selenium Implicit Wait
[Return] ${sec}
获取Selenium超时
${timeout} Get Selenium Timeout
[Return] ${timeout}
获取Selenium速率
${res} Get Selenium Speed
[Return] ${res}
获取xpath匹配次数
[Arguments] ${xpath}
${count} Get Matching Xpath Count ${xpath}
[Return] ${count}
获取元素值
[Arguments] ${locator}
${value} Get Value ${locator}
[Return] ${value}
获取元素属性
[Arguments] ${attribute_locator}
Get Element Attribute ${attribute_locator}
获取元素文本
[Arguments] ${locator}
${text} Get Text ${locator}
[Return] ${text}
获取坐标
${location} Get Location
[Return] ${location}
获取垂直坐标
[Arguments] ${locator}
${vertical} Get Vertical Position ${locator}
[Return] ${vertical}
获取当前Url
${url} Log Location
[Return] ${url}
获取当前页面标题
${title} Log Title
[Return] ${title}
获取所有Cookie
@{cookies} Get Cookies
[Return] @{cookies}
获取所有连接
@{links} Get All Links
[Return] @{links}
获取文本
[Arguments] ${path}
${text} get text ${path}
[Return] ${text}
获取标题
${title} get title
[Return] ${title}
获取水平坐标
[Arguments] ${locator}
@{position} Get Horizontal Position ${locator}
[Return] @{position}
获取焦点
[Arguments] ${locator}
Focus ${locator}
获取窗口名字
@{names} Get Window Names
[Return] @{names}
获取窗口坐标
${x} ${y}= Get Window Position
[Return] ${x} ${y}
获取窗口大小
${width} ${higth}= GET Window Size
[Return] ${width} ${higth}
获取窗口标识
@{windows} Get Window Identifiers
[Return] @{windows}
获取窗口标题
@{titles} Get Window Titles
[Return] @{titles}
获取表格内容
[Arguments] ${table_locator} ${row} ${column} ${loglevel}=INFO
${cell} Get Table Cell ${table_locator} ${row} ${column} ${loglevel}
[Return] ${cell}
获取警告信息
${msg} Get Alert Message
[Return] ${msg}
获取资源
${source} Get Source
[Return] ${source}
获取页面元素
[Arguments] ${locator}
@{elements} Get Webelements ${locator}
[Return] @{elements}
获取页面标题
${title} Get Title
[Return] ${title}
获取页面资源
[Arguments] ${loglevel}=INFO
${source} Log Source ${loglevel}
[Return] ${source}
表头应该包含
[Arguments] ${table_locator} ${expected} ${loglevel}=INFO
table header should contain ${table_locator} ${expected} ${loglevel}
表头应该包含文本
[Arguments] ${table_locator} ${expected} ${loglevel}=INFO
Table Header Should Contain ${table_locator} ${expected} ${loglevel}
表应该包含文本
[Arguments] ${table_locator} ${expected} ${loglevel}=INFO
Table Should Contain ${table_locator} ${expected} ${loglevel}
表格Footer应该包含文本
[Arguments] ${table_locator} ${expected} ${loglevel}
Table Footer Should Contain ${table_locator} ${expected} ${loglevel}
表格列应该包含文本
[Arguments] ${table_locator} ${col} ${expected} ${loglevel}=INFO
Table Column Should Contain ${table_locator} ${col} ${expected} ${loglevel}
表格应该包含
[Arguments] ${table_locator} ${row} ${column} ${expected}
table cell should contain ${table_locator} ${row} ${column} ${expected}
表格应该包含文本
[Arguments] ${table_locator} ${row} ${column} ${expected} ${loglevel}=INFO
Table Cell Should Contain ${table_locator} ${row} ${column} ${expected} ${loglevel}
表格行应该包含文本
[Arguments] ${table_locator} ${row} ${expected} ${loglvl}=INFO
Table Row Should Contain ${table_locator} ${row} ${expected} ${loglvl}
设置Selenium等待
[Arguments] ${seconds}
${return} Set Selenium Implicit Wait ${seconds}
[Return] ${return}
设置Selenium超时
[Arguments] ${seconds}
Set Selenium Timeout ${seconds}
设置Selenium速率
[Arguments] ${speed}
Set Selenium Speed ${speed} seconds
设置浏览器等待时间
[Arguments] ${seconds}
Set Browser Implicit Wait ${seconds}
设置窗口坐标
[Arguments] ${x} ${y}
Set Window Position ${x} ${y}
设置窗口大小
[Arguments] ${width} ${higth}
Set Window Size ${width} ${higth}
跳转
[Arguments] ${url}
Go To ${url}
跳转到
[Arguments] ${url}
go to ${url}
输入密码
[Arguments] ${path} ${passwd}
Input password ${path} ${passwd}
输入文本
[Arguments] ${path} ${str}
Input Text ${path} ${str}
选择Checkbox
[Arguments] ${locator}
Select Checkbox ${locator}
选择Frame
[Arguments] ${locator}
Select Frame ${locator}
选择Radio按钮
[Arguments] ${group_name} ${value}
Select Radio Button ${group_name} ${value}
选择文件
[Arguments] ${locator} ${file_path}
Choose File ${locator} ${file_path}
选择窗口
[Arguments] ${locator}=
Select Window ${locator}
页面应该不包含Checkbox
[Arguments] ${locator} ${msg}= ${loglevel}=INFO
Page Should Not Contain Checkbox ${locator} ${msg} ${loglevel}
页面应该不包含Link
[Arguments] ${locator} ${msg}= ${loglevel}=INFO
Page Should Not Contain Link ${locator} ${msg} ${loglevel}
页面应该不包含List
[Arguments] ${locator} ${msg}= ${loglevel}=INFO
Page Should Not Contain List ${locator} ${msg} ${loglevel}
页面应该不包含Radio按钮
[Arguments] ${locator} ${msg}= ${loglevel}=INFO
Page Should Not Contain Radio Button ${locator} ${msg} ${loglevel}
页面应该不包含元素
[Arguments] ${locator} ${msg}= ${loglevel}=INFO
Page Should Not Contain Element ${locator} ${msg} ${loglevel}
页面应该不包含图片
[Arguments] ${locator} ${msg}= ${loglevel}=INFO
Page Should Not Contain Image ${locator} ${msg} ${loglevel}
页面应该不包含按钮
[Arguments] ${locator} ${msg}= ${loglevel}=INFO
Page Should Not Contain Button ${locator} ${msg} ${loglevel}
页面应该不包含文本
[Arguments] ${text} ${lvl}=INFO
Page Should Not Contain ${text} ${lvl}
页面应该不包含文本框
[Arguments] ${locator} ${msg}= ${loglevel}=INFO
Page Should Not Contain Textfield ${locator} ${msg} ${loglevel}
页面应该包含Checkbox
[Arguments] ${locator} ${msg}= ${loglevel}=INFO
Page Should Contain Checkbox ${locator} ${msg} ${loglevel}
页面应该包含Link
[Arguments] ${locator} ${msg}= ${loglevel}=INFO
Page Should Contain Link ${locator} ${msg} ${loglevel}
页面应该包含List
[Arguments] ${locator} ${msg}= ${loglevel}=INFO
Page Should Contain List ${locator} ${msg} ${loglevel}
页面应该包含Radio按钮
[Arguments] ${locator} ${msg}= ${loglevel}=INFO
Page Should Contain Radio Button ${locator} ${msg} ${loglevel}
页面应该包含元素
[Arguments] ${locator} ${msg}= ${loglevel}=INFO
Page Should Contain Element ${locator} ${msg} ${loglevel}
页面应该包含图片
[Arguments] ${locator} ${msg}= ${loglevel}=INFO
Page Should Contain Image ${locator} ${msg} ${loglevel}
页面应该包含按钮
[Arguments] ${locator} ${msg}= ${loglevel}=INFO
Page Should Contain Button ${locator} ${msg} ${loglevel}
页面应该包含文本
[Arguments] ${text} ${loglevel}=INFO
Page Should Contain ${text} ${loglevel}
页面应该包含文本框
[Arguments] ${locator} ${msg}= ${loglevel}=INFO
Page Should Contain Textfield ${locator} ${msg} ${loglevel}
鼠标悬停
[Arguments] ${locator}
Mouse Over ${locator}
鼠标移出
[Arguments] ${locator}
Mouse Out ${locator}
鼠标释放
[Arguments] ${locator}
Mouse Up ${locator}
Appium+RobotFramework常用关键字
Open Application,启动指定app
要想打开模拟器或手机上的指定app,则需要使用open application方法,这里,对这个方法进行简单的介绍:
1.http://localhost:4723/wd/hub:
Appium所在的url路径(这里appium搭建在本机,所以url格式固定不变)
2.platformName:
被测的平台名称,Android或ios
3.platformVersion:
平台版本,如Android的版本号
4.deviceName:
设备名称,即运行得模拟器或真机的设备型号
5.app:
被测应用的存储路径
6.appPackage:
app的包名
7.appActivity:
app的activity名
注:关于app的包名及activity名的获取方法,在本博客的Monkeyrunner的学习中,有介绍过;请参考Monkeyrunner中的方法。
8、实参获取方法
1)deviceName获取
通过在cmd命令行中,输入adb devices指令获取
2)app
与appPackage和appActivity,可以二选一;即选择填写appPackage和appActivity参数时,可省略app参数,不填写;不填写app时,默认被测设备中,已经有该app的存在;填写app该参数时,系统会重新安装指定app
3)appPackage
方法一:通过uiautomatorviewer获取
方法二:aapt dump badging [apk在电脑本地存储路径],apk路径中一定不能有空格(具体参考:http://www.cnblogs.com/lynn-li/p/5885001.html中的“如何获取一个app的package名和activity”)
4)appActivity
方法一:aapt dump badging [apk在电脑本地存储路径],apk路径中一定不能有空格(具体参考:http://www.cnblogs.com/lynn-li/p/5885001.html中的“如何获取一个app的package名和activity”)
方法二:打开首页activity name,获取命令adb logcat ActivityManager:I*:s
到此,我们已经可以成功打开指定设备上的特定app。
常用关键字
一、实用函数
关键字 |
含义 |
实例 |
备注 |
Click Button |
点击按钮 |
Click Button 注销 |
这里“注销”的class属性,必须是Button |
Click Element |
点击元素 |
Click Element [locator] |
Locator可以是resource-id,也可以是xpath;但必须是当前页面唯一存在的;一般用该关键字可以完成所有元素点击 |
Click Text |
点击文字 |
Click Text 我的 |
“我的”需要是当前页面唯一存在的 |
Input Text |
在指定元素中输入文本 |
InputText [locator] 111111 |
Locator可以是resource-id,也可以是xpath |
Swipe |
滑动屏幕 |
Swipe 1000 1800 100 1800
|
|
Get Text |
获取某标签内容 |
${account} Get Text [locator] |
获取内容后存储到指定变量中,从而在后续脚本中调用该内容 |
二、校验函数
关键字 |
含义 |
实例 |
备注 |
Element Name Should Be |
检查元素的name属性
|
Element Name Should Be [locator] 登录 |
locator可以是resource-id,也可以是xpath |
Element Should Be Enabled |
检查元素是否可用/可见 |
Element Should Be Enabled [locator] |
|
Page Should Contain Element |
检查界面包含某些元素 |
Page Should Contain Element [locator] |
|
Page Should Contain Text |
检查界面包含某些文字信息 |
Page Should Contain Text 预约挂号 |
|
Page Should Not Contain Element |
检查界面不包含某些元素 |
Page Should Not Contain Element [locator] |
|
Page Should Not Contain Text |
检查界面不包含某些文字信息 |
Page Should Not Contain Text 预约挂号 |
|
三、等待函数
关键字 |
含义 |
实例 |
备注 |
Wait Until Page Contains |
等待直到界面中包含某些文字,才进行下一步 |
Wait Until Page Contains 预约挂号 |
默认等待时间为5s |
Wait Until Page Contains Element |
等待直到界面中包含某些元素,才进行下一步 |
Wait Until Page Contains Element [locator] |
locator可以是resource-id,也可以是xpath |
Wait Until Page Does Not Contain |
等待直到界面中不包含某些文字,才进行下一步 |
Wait Until Page Does Not Contain 预约挂号 |
|
Wait Until Page Does Not Contain Element
|
等待直到界面中不包含某些元素,才进行下一步 |
Wait Until Page Does Not Contain Element [locator]
|
|
使用小结:
如何输入中文
方法:
在open application参数最后,新增unicodeKeyboard=True resetKeyboard=True;不加入这两个参数时,中文无法输入
linux上配置robotframework环境及selenium2library
1.首先安装python,我安装的是python2.7,python安装方法不再赘述
2.安装pip
wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py;python get-pip.py
3.使用pip安装robotframework及selenium2library
pip install pyvirtualdisplay selenium robotframework
pip install robotframework
pip install robotframework-selenium2library
4.安装火狐浏览器及火狐driver
wget https://github.com/mozilla/geckodriver/releases/download/v0.24.0/geckodriver-v0.24.0-linux64.tar.gz
tar -zxf geckodriver-v0.24.0-linux64.tar.gz
mv geckodriver /usr/local/bin/
yum install firefox
火狐driver更新下载链接如下:https://github.com/mozilla/geckodriver/releases
5.安装完成后,编写简单脚本进行测试(打开百度):
*** Settings ***
Library Selenium2Library
*** Test Cases ***
open_baidu
Open Browser https://www.baidu.com/ headlessfirefox
将该内容保存为open_baidu.robot,然后运行:
运行成功,安装配置成功
mac下使用robotframework-selenium2library做web自动化
1.pip 安装robotframework-selenium2library
2.下载相应的googlechrome.dmg(V58)
http://dl.pconline.com.cn/download/54621-1.html
3.下载相应的chromedriver(我用的2.29)
http://chromedriver.storage.googleapis.com/index.html
4.把chromedriver放到/usr/local/bin目录下
5.引用Selenium2Library,开始写自动化用例吧
验证
open browser |
http://www.baidu.com |
chrome |
${title} |
Get Title |
|
should contain |
${title} |
百度一下,你就知道 |
Open Browser 通过chrome打开百度首页。
Get Title 获得浏览器窗口的titile ,并赋值给变量${title}
Should Contain 比较${title}是否等于“百度一下,你就知道”。
如果item1 不包含 item2 一次或多次,那么失败。
表单嵌套
Select Frame |
Xpath=//* [@] |
|
Unselect Frame |
|
|
Select Frame 进入表单,Xpath=//* [@] 表示定位要进入的表单。
Unselect Frame 退出表单。
下拉框选择
Unselect From List By Value |
Xpath=//* [@] |
vlaue |
|
|
|
Xpath=//* [@] 定位下拉框;
Vlaue 选择下拉框里的属性值。
cookie处理
获取cookie
get cookies |
|
|
获得当前浏览器的所有cookie 。
获得cookie值
get cookie value |
Key_name |
|
Key_name : key_name 表示一对cookie中key的name 。
删除cookie
delete cookie |
Key_name |
|
删除key为name 的cookie信息。
删除所有cookies
delete all cookies |
|
|
删除当前浏览器的所有cookie。
添加cookie
add cookie |
Key_name |
Value_name |
添加一对cooke (key:value)
等待元素出现在当前页面
Wait Until Page Contains Element |
Xpath=//* [@] |
42 |
error |
Xpath=//* [@] :表示元素定位,这里定位出现的元素
42 : 表示最长等待时间。
Error : 表示错误提示,自定义错误提示,如:“元素不能正常显示”
点击元素
Click Element |
Xpath=//* [@] |
|
Xpath=//* [@] :表示元素定位,定位点击的元素。
点击按钮
Click Button |
Xpath=//* [@] |
|
Xpath=//* [@] :表示元素定位,定位点击的按钮。
设置浏览器宽、高
Get Window Size |
800 |
600 |
以像素为单位,第一个参数800表示宽度,第二个参数600表示高度。
文本输入
Input Text |
Xpath=//* [@] |
输入信息 |
Xpath=//* [@] :表示元素定位,定位文本输入框。
通过不同的浏览器执行脚本。
浏览器驱动
Open Browser |
Htpp://www.xxx.com |
chrome |
浏览器对应的关键字:
firefox |
FireFox |
ff |
|
internetexplorer |
Internet Explorer |
ie |
|
googlechrome |
Google Chrome
|
gc |
|
chrome |
|
opera |
Opera |
phantomjs |
PhantomJS |
htmlunit |
HTMLUnit |
htmlunitwithjs |
HTMLUnit with Javascipt support |
android |
Android |
iphone |
Iphone |
safari |
Safari |
备注:
要想通过不同的浏览打开URL地址,一定要安装浏览器相对应的驱动。如chrome 的驱动:
chromedriver.exe 等。
浏览器默认为空时启动FireFox。
Roboframework - Selenium - 查找所有包含特定文本的 HREF
问题是您混合使用了 xpath 和 CSS。您使用的选择器是一个 CSS 选择器,然后您将它作为 XPATH 传递。所以你可以通过两种方式做到这一点
XPATH
Get WebElements xpath://a[contains(@href,'photo/?fbid')]
CSS
Get WebElements css:a[href*='photo/?fbid']
今天关于RobotFramework Selenium2 关键字和robotframework关键字编写的分享就到这里,希望大家有所收获,若想了解更多关于Appium+RobotFramework常用关键字、linux上配置robotframework环境及selenium2library、mac下使用robotframework-selenium2library做web自动化、Roboframework - Selenium - 查找所有包含特定文本的 HREF等相关知识,可以在本站进行查询。
本文标签: