关键词不能为空

当前您在: 主页 > 英语 >

Selenium 中文手册

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-28 05:32
tags:

-

2021年2月28日发(作者:linear)


五、


Selenium


中文手册



Commands (


命令


)



Action


对当前状态进行操作



失败时,停止测试



Assertion


校验是否有产生正确的值



Element Locators


指定

HTML


中的某元素



Patterns


用于模式匹配



1. Element Locators (


元素定位器


)



id=id


id locator


指定


HTML


中的唯一


id

< p>
的元素



name=name


name locator


指定



HTML


中相同


name

< br>的元素中的第一个元素



identifier=id


identifier locator


首先查找

< p>
HTML


是否存在该


id


的元素


,


若不存在,


查找第一个该< /p>


name


的元




dom=javascriptExpression


dom locator



JavaScript


表达式来定位


HTML


中的元素


,< /p>


注意必须要以



开头



例如


:


dom=['myForm'].myDropdown


dom=[56]



xpath=xpathExpression


xpath locator



XPath


表达式来 定位


HTML


中的元素


,


必须注意要以



开头



例如:



xpath=//img[@alt='The image alt text']


xpath=//table[@id='table1']//tr[4]/td[2 ]



link=textPattern


link locator



lin k


来选择


HTML


中的连接或锚元素< /p>



例如


:


link=The link text


在没有


locator


前序的情况下



Without a locator prefix, Selenium uses:


如果以



开头,则默认是使 用


dom locator


,如果是以



开头,则默认使用


xpath


loc ator,


其余情况均认作


identifier locator



2. String Matching Patterns (


字符串匹配模式


)



glob:patthern


glob


模式,用通配符



代表任意长度字符,



代表一个字符



regexp:regexp


正则表达式模式,用

< p>
JavaScript


正则表达式的形式匹配字符串



exact:string


精确匹配模式,精确匹配整个字符串,不能用通配符



在没有指定字符串匹配前序的时候,


selenium


默认使用


golb


匹配模式

< br>


3. Select Option Specifiers (Select


选项指定器


)



label=labelPattern


通过匹配选项中的文本指定选项



例如 :


label=regexp:^[Oo]ther



value=valuePattern


通过匹配选项中的值指定选项



例如:


value=other



id=id


通过匹配选项的


id


指定选项



例如


: id=option1



index=index

< p>
通过匹配选项的序号指定选项,序号从


0


开始



例如:


index=2



在没有选项选择前序的情况下,默认是匹配选项的文本



Actions



描述了用户所会作出的操作。



Action


有两种形式


: action



actionAndWait, action


会立即执行,而


actionAndWait

< br>会假设需


要较长时间才能得到该


action

< p>
的相响,而作出等待,


open


则是会自动处理等 待时间。



click


click(elementLocator)


-


点击连接


,


按钮,复选和单选框



-


如果点击后需要等待响应,则用



- < /p>


如果是需要经过


JavaScript



alert



confirm


对话框后才能继续操作,则需要调用


verify



assert


来告诉


Seleni um


你期望对对话框进行什么操作。



click



aCheckbox






clickAndWait



submitButton



clickAndWait



anyLink



open


open(url)


-


在浏览器中 打开


URL,


可以接受相对和绝对路径两种形式



-


注意:该


URL


必须在与浏览器相同的安全限定范围之内



open


/



mypage



open


h



ttp://localhost/




type


type(inputLocator, value)


-


模拟人手的输入过程,往指定的

< p>
input


中输入值



-


也适合给复选和单选框赋值



-


在这个例子中,则只是给钩选了的复选框赋值,注意,而不是改写其文本


type



nameField



John Smith



typeAndWait



textBoxThatSubmitsOnChange



newValue



select


select(dropDownLocator, optionSpecifier)


-


根据


optionSpecifier


选项选择器来选择一个下拉菜单选项



-


如果有多于一个选择器的时候,如在用通 配符模式,如



或者超过一个选项有相同的


文本或值,则会选择第一个匹配到的值



select



select



dropDown



dropDown



Australian Dollars



index=0



selectAndWait



currencySelector



value=AUD



selectAndWait



currencySelector



label=Auslian D*rs



goBack,close


goBack()


模拟点击浏览器的后退按钮



close()


模拟点击浏览器关闭按钮



selectWindow


select(windowId)


-


选择一个弹出窗口



-


当选中那个窗口的时候,所有的命令将会转移到那窗口中执行



selectWindow



myPopupWindow



selectWindow



null



pause


pause(millisenconds)




-


根据指定时间暂停


Selenium


脚本执行



-


常用在调试脚本或等待服务器段响应时



pause


5



000




pause


2



000




fireEvent


fireEvent(elementLocatore,evenName)


模拟页面元素事件被激活的处理动作



fireEvent



textField



focus



fireEvent



dropDown



blur



waitForCondition


waitForCondition(JavaScriptSnippet,time)


-


在限定时间内,等待一段


Java Script


代码返回


true


值,超 时则停止等待



waitForCondition



var value=t(


3



000



waitForValue


waitForValue(inputLocator, value)


-


等待某


input(



hidden input)


被赋予某值,



-


会轮流检测该值,所以要注意如果该值长时间一直不赋予该


inpu t


该值的话,可能会导致


阻塞



waitForValue



finishIndication



isfinished



store,stroreValue

-


-


-


-


-


-


-


-



本文更新与2021-02-28 05:32,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/678934.html

Selenium 中文手册的相关文章