|
String Matching Patterns(字符串匹配模式)
*glob:patthern
glob模式,用通配符"*"代表任意长度字符,"?"代表一个字符
*regexp:regexp
正则表达式模式,用JavaScript正则表达式的形式匹配字符串
*exact:string
精确匹配模式,精确匹配整个字符串,不能用通配符
* 在没有指定字符串匹配前序的时候,selenium默认使用golb匹配模式
Select Option Specifiers(Select 选项指定器)
*label =labelPattern
通过匹配选项中的文本指定选项(大小写)
如:label=regexp:^[Oo]ther
*value=valuePattern
通过匹配选项中的值指定选项
如:value=other
*id=id
通过匹配选项的id指定选项
如:id=option1
*index=index
通过匹配选项的序号指定选项,序号从0开始
如:index=2;
*在没有选项选择前序的情况下,默认是匹配选项的文本
Actions
描述了用户所做的操作
Action有两种形式:action和actionAndWait,action会立即执行,而actionAndWait会假设需要较长时间才能得到该action的响应,而作出的等待,open则是会自动处理等待时间。
*click
click(elementLocator)
- 点击连接按钮,复选和单选框
- 如果点击后需要等待响应,则用"clickAndWait"
- 如果是需要经过JavaScript的alert或confirm对话框后才能继续操作,则需要条用verify或assert来告诉Selenium你期望对对话框进行什么操作
*open
open(url)
- 在浏览器中打开URL,可以接受相对和绝对路径两种形式
- 注意:该URL必须在于浏览器相同的安全限定范围之内
open /mypage
open http://localhost/
*type
type(inputLocator,value)
-模拟人手的输入过程,往指定的input中输入值
- 也适合给复选和单选框赋值
- 在这个例子中,则只是给勾选了的复选框赋值,注意,而不是改写其文本
*select
select(dropDownLocator,optionSpecifier)
- 根据optionSpecifier选项选择器来选择一个下拉菜单选项
- 如果有多于一个选择器的时候,如在用通配符模式,如"f*b*",或者超过一个选项有相同的文本或值,则会选择第一个匹配到的值
*goBack,close
goBack()
模拟点击浏览器的后退按钮
close()
模拟点击浏览器关闭按钮
*selectWindow
select(windowId)
- 选择一个弹出窗口
- 当选中那个窗口的时候,所有的命令将会转移到那个窗口中执行
*pause
pause(millisenconds)
- 根据指定时间暂停Selenium脚本
- 常用在调试脚本或等待服务器端响应时
pause 500
pause 200
*fireEvent
fireEvent(elementLocatore,evenName)
模拟页面元素事件被激活的处理动作
fireEvent(textField,focus)
fireEvent(dropDown,blur)
*waitForCondition
waitForCondition(JavaScriptSnipper,time)
- 在限定时间内,等待一段JavaScript代码返回true值,超时则停止等待
eg:waitForCondition(var value = selenium.getText("foo");value.match(/bar/);3000)
*waitForValue
waitForValue(inputLocator,value)
- 等待某input(如hidden input)被赋予某值,
- 会轮流检测该值,所以要注意如果该值长时间一直不赋予该input值得发,可能会导致阻塞
waitForValue (finishIndication,isfinished)
*store,stroeValue
store(valueToStore,variablename)
保存一个值到变量里
该值可以由其他变量组合而成或通过JavaScript表达式赋值给变量
store(Mr John Smith,fullname)
store($.{title} $.{firtname} $.{suname},fullname)
store(javascript.{Math.round(Math.PI*100)/100},PI)
storeValue(inputLocator,variableName)
把指定的input中的值保存到变量中
storeValue userName userID
type userName $.{userID}
*storeText,storeAttribute
storeText(elementLocator,variablename)
把指定元素的文本值赋予给变量
storeText(currentDate,expectedStartDate)
verifyValue(startDate,$.{expectedStartDate})
storeAttribute(.{} elementLocator@attributeName,variableName.{})
把指定元素的属性的值赋予给变量
storeAttribute(input1@class,classOfInput1)
verifyAttribute (input2@class ,$.{classOfInput1})
*chooseCancel..,answer...
chooseCancelOnNextConfirmation()
- 当下次JavaScript弹出confirm对话框的时候,让selenium选择Cancel
- 如果没有该命令时,遇到confirm对话框Selenium默认返回true,如手动选择OK按钮一样
chooseCancelOnNextConfirmation
- 如果已经运行过该命令,当下一次又有confirm对话框出现时,也会同样地再次选择Cancel
answerOnNextPrompt(answerString)
- 在下次JavaScript弹出prompt提示框时,赋予其anwerString的值,病选择确定