Selenium常用的命令(6)
2013-11-19 10:47
295 查看
下面是我觉得比较常用的命令:
1.open(url)
命令作用:打开网页,可以有相对和绝对路径两种形式
参数说明:url是要打开的网页的网址
例:要打开bing的首页,BaseURL为http://cn.bing.com/
2.type(inputLocator,value)
命令作用:在一个文本框中输入值
参数说明:inputLocator为UI元素的定位,value是要输入的值
例:在bing的首页中输入“selenium”
3.click(elementLocator)
命令作用:点击连接,按钮,复选和单选框
参数说明:elementLocator为UI元素的定位
例:点击bing的首页的“搜索“,BaseURL为http://cn.bing.com/
4.goBack()
命令作用:模拟网页的后退功能
参数说明:
例:
5.close()
命令作用:模拟浏览器的关闭功能
参数说明:
例:
6.select(dropDownLocator, optionSpecifier)
命令作用:选择一个下拉菜单选项
参数说明:dropDownLocator为UI元素的定位,optionSpecifier是选择项
例:打开开心网,选择“年份“为2013年,BaseURL 为http://www.kaixin001.com/
7.check(locator)
命令作用:勾选或者是取消checkbox或者是radio
参数说明:locator为UI元素的定位
例:打开开心网,选择“我现在“为”其他”,BaseURL 为http://www.kaixin001.com/
8.store(expression, variableName)
命令作用:保存一个值到一个变量里
参数说明:expression 为要保存的值,variableName为变量
例:
在其他命令的value中访问这个变量的值,方法是${id},例如
注意:在网上复制的或者是用中文输入$.{title},得到的可能不是变量的值,而是变量本身的字符串。如图:
所以一定要用英文输入${id}。 该值还可以由自其他变量组合而成或通过JavaScript表达式赋值给变量
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="">
执行结果:
[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>
执行结果:
[info] echo: 注册新账号
<input type="submit" id="btn_dl" value="登 录" title="登录"class="newFormBtn_red2" onclick="">
执行结果:
[info] echo:
11. waitForValue(inputLocator,value)
命令作用:等待某input(如hiddeninput)被赋予某值
参数说明:inputLocator元素的定位,value为预期的值
12. waitForCondition(inputLocator,value)
还有很多的命令,边学习边总结吧。
1.open(url)
命令作用:打开网页,可以有相对和绝对路径两种形式
参数说明:url是要打开的网页的网址
例:要打开bing的首页,BaseURL为http://cn.bing.com/
command | target | value |
open | / |
命令作用:在一个文本框中输入值
参数说明:inputLocator为UI元素的定位,value是要输入的值
例:在bing的首页中输入“selenium”
command | target | value |
type | sb_form_q | selenium |
typeAndWait | sb_form_q | selenium |
命令作用:点击连接,按钮,复选和单选框
参数说明:elementLocator为UI元素的定位
例:点击bing的首页的“搜索“,BaseURL为http://cn.bing.com/
command | target | value |
click | sb_form_go |
命令作用:模拟网页的后退功能
参数说明:
例:
command | target | value |
goBack() |
命令作用:模拟浏览器的关闭功能
参数说明:
例:
command | target | value |
close() |
命令作用:选择一个下拉菜单选项
参数说明:dropDownLocator为UI元素的定位,optionSpecifier是选择项
例:打开开心网,选择“年份“为2013年,BaseURL 为http://www.kaixin001.com/
command | target | value |
select | year | index=1 |
select | year | value=2013 |
select | year | label=2013 |
命令作用:勾选或者是取消checkbox或者是radio
参数说明:locator为UI元素的定位
例:打开开心网,选择“我现在“为”其他”,BaseURL 为http://www.kaixin001.com/
command | target | value |
check | other |
命令作用:保存一个值到一个变量里
参数说明:expression 为要保存的值,variableName为变量
例:
Command | Target | Value |
store | 123 | id |
Command | Target | Value |
type | regemailinput | ${id} |
所以一定要用英文输入${id}。 该值还可以由自其他变量组合而成或通过JavaScript表达式赋值给变量
Command | Target | Value |
store | 123 | id |
store | 456 | id2 |
store | ${id}${id2} | id3 |
store | javascript{Math.round(Math.PI*100)/100} | id4 |
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 | email |
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)
还有很多的命令,边学习边总结吧。
相关文章推荐
- android 实现zip文件的解压
- 使用AES对文件的加解密
- 终于把你必须知道的.NET看完了
- 如何设置gen_server在退出时执行相关操作
- Poj 1015
- 《文字与段落——使用HTML标记完成页面排版》
- 面向对象编程(OOP)
- Android 滑动切换页面-ViewFlipper
- python学习
- AS3 Graphics 多次绘制
- HDOJ 2222 Keywords Search
- python 解析 crontab配置
- Android异步消息处理机制完全解析,带你从源码的角度彻底理解
- iframe防止嵌套
- text rendering
- mac系统如何显示和隐藏文件
- mysql和eclipse都设置了utf8编码,保存时中文依然乱码
- AS3 读写 C++ 64位数字
- 面试中如何运用实践经验
- 分享一篇关于iOS7力学的文章