Selenium常用的命令(6)
来源:互联网 发布:php一键环境搭建 编辑:程序博客网 时间:2024/05/21 09:28
下面是我觉得比较常用的命令:
1.open(url)
命令作用:打开网页,可以有相对和绝对路径两种形式
参数说明:url是要打开的网页的网址
例:要打开bing的首页,BaseURL为http://cn.bing.com/
2.type(inputLocator,value)commandtargetvalueopen/
命令作用:在一个文本框中输入值
参数说明:inputLocator为UI元素的定位,value是要输入的值
例:在bing的首页中输入“selenium”
commandtargetvaluetypesb_form_qseleniumtypeAndWaitsb_form_qselenium
3.click(elementLocator)
命令作用:点击连接,按钮,复选和单选框
参数说明:elementLocator为UI元素的定位
例:点击bing的首页的“搜索“,BaseURL为http://cn.bing.com/
commandtargetvalueclicksb_form_go
4.goBack()
命令作用:模拟网页的后退功能
参数说明:
例:
commandtargetvaluegoBack()
5.close()
命令作用:模拟浏览器的关闭功能
参数说明:
例:
commandtargetvalueclose()
6.select(dropDownLocator, optionSpecifier)
命令作用:选择一个下拉菜单选项
参数说明:dropDownLocator为UI元素的定位,optionSpecifier是选择项
例:打开开心网,选择“年份“为2013年,BaseURL 为http://www.kaixin001.com/
commandtargetvalueselectyearindex=1selectyearvalue=2013selectyearlabel=2013
7.check(locator)
命令作用:勾选或者是取消checkbox或者是radio
参数说明:locator为UI元素的定位
例:打开开心网,选择“我现在“为”其他”,BaseURL 为http://www.kaixin001.com/
commandtargetvaluecheckother
命令作用:保存一个值到一个变量里
参数说明:expression 为要保存的值,variableName为变量
例:
Command
Target
Value
store
123
id
在其他命令的value中访问这个变量的值,方法是${id},例如
Command
Target
Value
type
regemailinput
${id}
注意:在网上复制的或者是用中文输入$.{title},得到的可能不是变量的值,而是变量本身的字符串。如图:
所以一定要用英文输入${id}。 该值还可以由自其他变量组合而成或通过JavaScript表达式赋值给变量
Command
Target
Value
store
123
id
store
456
id2
store
${id}${id2}
id3
store
javascript{Math.round(Math.PI*100)/100}
id4
id3为“123456”,id4为3.14
9. storeValue(locator, variableName)
命令作用:locator为表单元素,也就是input元素的值,也就是属性value的值,其中checkbox/radio元素为“off/on“,select为空
参数说明:locatorUI元素定位,variableName为变量
例:text
<input style="font-family: Arial; color:rgb(204, 204, 204); font-weight: normal;" name="loginemail"value="" type="text" size="18"class="it1" onfocus="this.className='it2';" onblur="this.className='it1';"data-result="">
Command
Target
Value
storeValue
loginemail
echo
${email}
执行结果:
[info] echo: 邮箱/手机号/其他用户名
其他例子:
执行结果:
l [info] Executing:|open | / | |
l [info] Executing:|storeValue | loginemail | email |
l [info] Executing:|echo | ${email} | |
l [info] echo: 邮箱/手机号/其他用户名
l [info] Executing:|storeValue | month | value_select |
l [info] Executing:|echo | ${value_select} | |
l [info] echo:
l [info] Executing:|storeValue | man | man |
l [info] Executing:|echo | ${man} | |
l [info] echo: off
l [info] Executing:|storeValue | women | women |
l [info] Executing:|echo | ${women} | |
l [info] echo: on
l [info] Executing:|storeValue | status | status |
l [info] Executing:|echo | ${status} | |
l [info] echo: off
l [info] Executing:|storeValue | rcode2 | hidden |
l [info] Executing:|echo | ${hidden} | |
l [info] echo:
l [info] Executing:|storeValue | password | password |
l [info] Executing:|echo | ${password} | |
l [info] echo:
l [info] Executing:|storeValue | btn_dl | submit |
l [info] Executing:|echo | ${submit} | |
l [info] echo: 登 录
l [info] Executing:|storeValue | //a[@title='注册新账号'] | a |
l [error] Thiselement has no value; is it really a form field?
10. storeText(locator,variableName)
命令作用:保存页面中元素的text值
参数说明:locator元素的定位,variableName为变量
例:在开心网上,BaseURL 为http://www.kaixin001.com/, 要输出a的text,如下
<ahref="http://reg.kaixin001.com" title="注册新账号" class="newFormBtn_blue">注册新账号</a>
Command
Target
Value
storeText
//a[@title='注册新账号']
a_text
echo
${ a_text }
执行结果:
[info] echo: 注册新账号
<input type="submit" id="btn_dl" value="登 录" title="登录"class="newFormBtn_red2" onclick="">
Command
Target
Value
storeText
btn_dl
button_text
echo
${ button_text }
执行结果:
[info] echo:
11. waitForValue(inputLocator,value)
命令作用:等待某input(如hiddeninput)被赋予某值
参数说明:inputLocator元素的定位,value为预期的值
12. waitForCondition(inputLocator,value)
还有很多的命令,边学习边总结吧。
- Selenium常用的命令(6)
- Selenium常用的方法
- Selenium常用的方法
- Selenium命令(二)
- selenium中常用的xpath
- selenium中常用的xpath
- Selenium+常用的方法(Java)
- selenium常用控件的操作
- Selenium的一些常用操作
- Selenium常用方法的封装
- Selenium常用的方法总结
- selenium常用知识点(一)
- selenium常用知识点(二)
- selenium webdriver 学习总结-Selenium API常用(四)
- selenium webdriver 学习总结-Selenium API常用(四)
- selenium webdriver 学习总结-Selenium API常用(四)
- Selenium RC junit常用的方法
- selenium中常用的关键字总结
- JAVA API的扩展库详解
- SparkWeb源码下载以及编译详解
- (Relax 数论 1.1)POJ 2429 GCD & LCM Inverse(已知GCD、LCM,反求a、b)
- [转]Tomcat SSL配置及Tomcat CA证书安装
- 冒泡法排序的相关问题
- Selenium常用的命令(6)
- 很2的SQL问题
- elRTE使用方法,代码
- mac系统如何显示和隐藏文件
- 管理好你的论文
- text rendering
- JDK 1.5的新特性
- WPF、Silverlight项目中使用柱状图、饼状图、折线图
- Android 滑动切换页面-ViewFlipper