几个常用关键字的使用笔记(一)
一、
Get Element Count
获取相同element的个数(比如新建多个账户然后去删除时,判断可删除的画像个数,也就是说判断有多少个删除按钮)
其中:
element的写法为相同的前缀,不同的地方以*替代
e.g.:
//*[@id="app"]/div/div/section/div/div[1]/div[1]/span[2]/i
//*[@id="app"]/div/div/section/div/div[2]/div[1]/span[2]/i
//*[@id="app"]/div/div/section/div/div[3]/div[1]/span[2]/i
写为:
${x} Get Element Count //*[@id="app"]/div/div/section/div/div[*]/div[1]/span[2]/i
即为返回页面该层相同元素的个数
二、
Run Keyword And Return Status
获取后面关键字的返回状态,True/False
其中:
e.g.:
${judjement} Run Keyword And Return Status page should contain element //[@id="app"]/div/div/div/div[2]/div/div[2]/a/i
即为返回页面是否含有该元素的布尔值
三、
Create_List
构建列表
其中:
空值可以不写跳过就好了
e.g.:
@{address} Create List 2010 2011 2012 2013 2014
应用时需要加上下标(下标从0开始)
${x} Set Variable @{address}[1]
Log ${x}
为2011
四、
Create_Dictionary
构建字典
其中:
空格中填入的键值对形式。空value可以,空key不行,和dictionary一样。key不能重复
e.g.:
&{dic} Create Dictionary 年份1=2010 年份2=2011 年份3=2012
引用时需要加上key
${x} Set Variable &{dic}[年份1]
Log ${x}
为2010
五、
Element_Text_Should_Not_Be
元素包含的内容不包含
Arguments:
[ locator | not_expected | message=None | ignore_case=False ]
六、
Get Element Attribute
获取元素的属性值(id、class、type、style etc...)
Arguments:
[ locator | attribute ]
e.g.:
${e} Get Element Attribute //*[@id="app"]/div/div/div/div[3]/div[1]/ul/li[5]/a class
Log ${e}
为active
打印的结果是当前**的按钮的元素属性(即class="active")
七、
Element_Attribute_Value_Should_Be
获取元素的属性值并与预想值比较(断言)
其中:
Arguments:
[ locator | attribute | expected | message=None ]
e.g.:
Element Attribute Value Should Be //*[@id="app"]/div/div/div/div[3]/div[1]/ul/li[${i}]/a class active
其中${i}是循环取值后的变量
每次循环后取得当前的element的class的属性值需为active,则当前的断言通过
八、
Create List
构建列表
其实构建列表时,参数应该写${X},而不是写@{X},否则定义的不是一个List