前言:
而今姐妹们对“elementclear”大概比较看重,各位老铁们都想要学习一些“elementclear”的相关文章。那么小编也在网络上搜集了一些有关“elementclear””的相关文章,希望我们能喜欢,朋友们快快来学习一下吧!打开浏览器
# 常用浏览器简写(FrieFix:firefix、ff|Internet Explorer:internetexplorer、ie)
# 常用浏览器简写(Google Chrome:googlechrome、gc、chrome|Opera:opera|Safari:safari)
Comment 这个是注释
Open Browser Chrome
浏览器最大化
Maximize Browser Window
指定浏览器大小
Get Window Size
点击页面某个链接
Click Link Xpath://*[@id="su"]
获取所有窗口title
${title} Get Window Titles
点击页面某个按钮
Click Button name:kw
点击页面某个元素内容
Click Element id:su
输入框输入内容
Input Text Xpath://*[@id="su"] Huangcius
输入密码
Input Password Xpath://*[@id="su"] 123456
清除输入框内容
Clear Element Text Xpath://*[@id="su"]
等待时间
sleep 2
sleep 2minutes 10 seconds
等待页面元素出现在当前页面
Wait Until Page Contains Element id=nihao 42 Erro
等待页面元素可执行
Wait Until Element Is Enabled xpath=element_xpath
鼠标悬浮
Mouse Over xpath=element_xpath
选择页面中的frame和iframe框架内容
Select Frame id=topFrame
退出所有frame和iframe
Unselect Frame
检查页面是否包含某些内容
Page Should Contain 百度
检查frame框架是否包含某些内容
Frame Should Contain id=su 百度一下
Current Frame Should Contain 用户名
选择下拉框内容
Select From List By Value 20
Select From List By Index 1
Select From List By Label 每页20条
时间控件
Execute Javascript document.getElementById("datetime1").removeAttribute("readonly")
Execute Javascript document.getElementById("datetime1").value="2016-12-04"
选择复选框
Select Checkbox id:Checkbox
选择单选框
Select Radio Button group_name value
读取表格内容
Get Table Cell locator row column
判断表格中内容
Table Cell Should Contain locator row column expected
Table Column Should Contain locator column expected
Table Should Contain locator expected
上传文件
Choose File xpath=elemnet_xpath file_path
获取某一元素内容
${a} Get Text id=su
Log ${a}
获取页面标题
${b} Get Title
Log ${b}
获取页面URL
${url} Get Location
${urls} Get Locations
Log ${url}
Log ${urls}
获取元素属性值
Get Element Attribute id=kw@name @name
获取cookie
Get Cookies
获取cookie值
Get Cookie name
删除cookie
Delete Cookie name
删除所有cookie
Delete All Cookies
添加cookie
Add Cookie name value
变量赋值
${i} Set Variable Huang
Log ${i}
变量赋值比较
${登录信息} Set Variable 登录
${提示信息} Set Variable If ${登录信息}==登录成功 true false
输出内容
Log 2 # 输出某个值
Log Source # 输出当前页面源码内容
Log Location # 输出当前页面URL地址
关闭浏览器
Close Browser
Close All Browsers # 关闭所有浏览器
切换回旧的窗口
Select Window default
切换到新的窗口
Select Window new
切换到主窗口
Select Window MAIN
页面截图
Capture Page Screenshot
获取所有窗口句柄
@{allhandle} Get Window Handles
获取窗口的title
${titles} Get Window Titles
${titles2} Get From List ${titles} 1
${titles1} Get From List ${titles} 0
Log ${titles}
log ${titles2}
log ${titles1}
#切换到第二个窗口
Select Window title=${titles2}
#切换回第一个窗口,即搜索页面的那个窗口
Select Window title=${titles1}
选择某个窗口页面关闭该窗口
Select Window title=百度一下
Close Window
弹窗操作
Focus dom=$("div>a.pf").mouseenter()
Set Focus To Element dom=$("div>a.pf").mouseenter()
Sleep 2
Click Element jquery=div>a.setpref
Sleep 2
Click Element jquery=div>a[class='prefpanelgo']
Dismiss Alert true
弹框操作
${mes} Confirm Action
Choose Cancel On Next Confirmation
Execute Javascript Alert('test')
替换元素使用JS执行
Assign Id To Element name=login_username id=login_button
Execute Javascript setTimeout(function(){document.getElementById("login_button").click()},100)
断言校验
# 比较两个值相等或不相等
should be equal 实际结果 期望结果
should not be equal 实际结果 期望结果
# 判断以该内容开头或不是以该内容开头
should start with 欢迎开头 欢迎
should not start with 欢迎开头 欢迎
# 判断以该内容结尾或不是以该内容结尾
should end with 欢迎结尾 欢迎
should not end with 欢迎结尾 欢迎
# 页面的断言
Page Should Contain text 验证页面存在文本内容
Page Should Not Contain text 验证页面不存在文本内容
Element Should Be Disabled locator 验证元素被禁用
Element Should Be Enabled locator 验证元素可用
Element Should Be Visible locator message= 验证元素可见,不可见则输出message
Element Should Contain locator expected message= 验证元素包含expected,不包含则输出message
Element Text Should Be locator expected message= 验证元素完全包含expected,不完全包含则输出message
# 包含某个内容
${actresult} Get Text Xpath=element_xpath
should contain ${actresult} 指令已发送
页面向下滑动到指定位置
# [Arguments] ${hingt}
${js} Set Variable var q=document.documentElement.scrollTop=500
Execute Javascript ${js}
生成随机数字
${num} Evaluate random.randint(10000,99999) random
log ${num}
生成随机字符串
${str} evaluate string.ascii_letters string #大小写字母全部
# ${str} evaluate string.ascii_lowercase string #小写字母
log ${str}
${len} evaluate len('${str}')
log ${len}
${num} set variable 10
${name} set variable 2018
:FOR ${index} IN RANGE ${num}
\ ${i} evaluate random.randint(0,int(${len})-1) random
\ ${tmp} set variable ${str[int(${i})-1]}
\ ${newStr} set variable ${name}${tmp}
\ log ${name}
Press Key(键盘操作)
press key Xpath = /html/body/div[1]/div/div/section/div[1]/div[3]/div/input \ue007
# press key关键字后面的键位对应ascii码实际为16进制格式
# NULL = '\ue000'
# CANCEL = '\ue001'
# HELP = '\ue002'
# BACKSPACE = '\ue003'
# BACK_SPACE = BACKSPACE
# TAB = '\ue004'
# CLEAR = '\ue005'
# RETURN = '\ue006'
# ENTER = '\ue007'
# SHIFT = '\ue008'
# LEFT_SHIFT = SHIFT
# CONTROL = '\ue009'
# LEFT_CONTROL = CONTROL
# ALT = '\ue00a'
# LEFT_ALT = ALT
# PAUSE = '\ue00b'
# ESCAPE = '\ue00c'
# SPACE = '\ue00d'
# PAGE_UP = '\ue00e'
# PAGE_DOWN = '\ue00f'
# END = '\ue010'
# HOME = '\ue011'
# LEFT = '\ue012'
# ARROW_LEFT = LEFT
# UP = '\ue013'
# ARROW_UP = UP
# RIGHT = '\ue014'
# ARROW_RIGHT = RIGHT
# DOWN = '\ue015'
# ARROW_DOWN = DOWN
# INSERT = '\ue016'
# DELETE = '\ue017'
# SEMICOLON = '\ue018'
# EQUALS = '\ue019'
# NUMPAD0 = '\ue01a' # number pad keys
# NUMPAD1 = '\ue01b'
# NUMPAD2 = '\ue01c'
# NUMPAD3 = '\ue01d'
# NUMPAD4 = '\ue01e'
# NUMPAD5 = '\ue01f'
# NUMPAD6 = '\ue020'
# NUMPAD7 = '\ue021'
# NUMPAD8 = '\ue022'
# NUMPAD9 = '\ue023'
# MULTIPLY = '\ue024'
# ADD = '\ue025'
# SEPARATOR = '\ue026'
# SUBTRACT = '\ue027'
# DECIMAL = '\ue028'
# DIVIDE = '\ue029'
# F1 = '\ue031' # function keys
# F2 = '\ue032'
# F3 = '\ue033'
# F4 = '\ue034'
# F5 = '\ue035'
# F6 = '\ue036'
# F7 = '\ue037'
# F8 = '\ue038'
# F9 = '\ue039'
# F10 = '\ue03a'
# F11 = '\ue03b'
# F12 = '\ue03c'
# META = '\ue03d'
# COMMAND = '\ue03d'
创建列表和字典
# ${EMPTY}变量、@{EMPTY}列表、&{EMPTY}字典
@{list} Create List a b c
:FOR ${I} IN @{list}
\ Exit For Loop If ${i}=='b'
\ Log ${i}
&{dict} Create Dictionary a=Hello b=World
Log Many &{dict}
拼接字符串
${HelloWorld} Catenate Hello Robot
Log ${HelloWorld}
IF语句
${a} set variable 89
log ${a}
Run Keyword If ${a}>=90 log 优秀
... ELSE IF ${a}>=70 log 良好
... ELSE IF ${a}>=60 log 及格
... ELSE log 不及格
FOR语句
# ${EMPTY}变量、@{EMPTY}列表、&{EMPTY}字典
:FOR ${i} IN RANGE 10
\ Log ${i}
跳出FOR循环
@{list2} Create List a b c d
@{list} Create List a b c
:FOR ${I} IN @{list}
\ Exit For Loop If ${i}=='b'
\ Log ${i}
Run Keyword If使用
# 判断元素是否见
${元素是否可见} Run Keyword And Return Status Element Should Be Visible xpath=element_xpath
# 当元素可见时,返回true,继续执行如下操作
Run Keyword If ${元素是否可见} Run Keyword Clear Element Text xpath=element_xpath
Comment关键字使用
Comment 我是注释
Evaluate执行Python
${number} Evaluate random.randint(1000,9999) random
Log ${number}
ImportTest
Import Library E:/pythonTest/test.py
${a} Evaluate int(6)
${b} Evaluate int(8)
# ${add} add ${a} ${b}
# Log ${add}
获取时间方法
# 获取系统当前时间
${data} Get Current Date
${LastNDays} evaluate datetime.date.today()+ datetime.timedelta(days=-1) datetime
# 截取系统时间年月日
${str} Get Substring ${data} 0 10
# ${TodayDate} evaluate datetime.date.today().strftime('%Y%m%d') datetime
# 返回当前月的1号
${CurrentMonthFirstDay} evaluate datetime.date.today().replace(day=1) datetime
# 返回前一个月的1号
${LastMonthFirstDay} evaluate (datetime.date.today().replace(day=1) - datetime.timedelta(1)).replace(day=1) datetime #返回上月的1号
# 返回当前年份
${Year} evaluate datetime.date.today().year datetime
# 返回当前月份
${Month} evaluate datetime.date.today().month datetime
# 返回指定年和月的第一天是星期几
# 日从0(星期一)到6(星期日)月从1到12
${FirstDayforWeek} ${AllDaysForMonth} evaluate calendar.monthrange(${Year},${Month}) calendar
# 当前月份共计多少天
${NextMonthFirstDay} evaluate datetime.date.today().replace(day=1)+ datetime.timedelta(days=${AllDaysForMonth}) datetime #返回下月的1号
# 返回当前日期N天后的日期
${NextNDays} evaluate datetime.date.today()+ datetime.timedelta(days=N) datetime
# 返回当前日期N天前的日期
${LastNDays} evaluate datetime.date.today()+ datetime.timedelta(days=-N) datetime
# 获取上个月份
${LastMonth} evaluate ((datetime.date.today().replace(day=1) - datetime.timedelta(1)).replace(day=1)).strftime('%Y%m') datetime
# 获取下个月份
${NextMonth} evaluate (datetime.date.today().replace(day=1)+ datetime.timedelta(days=${AllDaysForMonth})).strftime('%Y%m') datetime
# 获取这个月最后1天日期
${MonthLastDay} evaluate datetime.date.today().replace(day=1)+ datetime.timedelta(days=${AllDaysForMonth}-1) datetime
# 获取上个月最后1天日期
${LastMonthLastDay} evaluate (datetime.date.today().replace(day=1) - datetime.timedelta(1)) datetime
# 获取下个月最后1天日期
${FirstDayforWeek} ${AllDaysForNextMonth} evaluate calendar.monthrange(${NextMonth[0:4]},${NextMonth[4:6]}) calendar
${NextMonthLastDay} evaluate datetime.date.today().replace(day=1)+ datetime.timedelta(days=${AllDaysForMonth})+ datetime.timedelta(days=${AllDaysForNextMonth}-1) datetime
标签: #elementclear