一、Commands (命令)
Action
對(duì)當(dāng)前狀態(tài)進(jìn)行操作
失敗時(shí),停止測(cè)試
Assertion
校驗(yàn)是否有產(chǎn)生正確的值
Element Locators
指定HTML中的某元素
Patterns
用于模式匹配
1.Element Locators (元素定位器)
id=id
id locator 指定HTML中的id的元素
name=name
name locator指定 HTML中相同name的元素中的第一個(gè)元素
identifier=id
identifier locator 首先查找HTML是否存在該id的元素, 若不存在,查找第一個(gè)該name的元素
dom=javascriptExpression
dom locator用JavaScript表達(dá)式來定位HTML中的元素,注意必須要以"document"開頭
例如:
dom=document.forms['myForm'].myDropdown
dom=document.images[56]
xpath=xpathExpression
xpath locator用 XPath 表達(dá)式來定位HTML中的元素,必須注意要以"//"開頭
例如:
xpath=//img[@alt='The image alt text']
xpath=//table[@id='table1']//tr[4]/td[2]
link=textPattern
link locator 用link來選擇HTML中的連接或錨元素
例如:
link=The link text
在沒有l(wèi)ocator前序的情況下 Without a locator prefix, Selenium uses:
如果以"document."開頭,則默認(rèn)是使用 dom locator,如果是以"//"開頭,則默認(rèn)使用xpath locator,其余情況均認(rèn)作identifier locator
2.String Matching Patterns (字符串匹配模式)
glob:patthern
glob模式,用通配符"*"代表任意長(zhǎng)度字符,"?"代表一個(gè)字符
regexp:regexp
正則表達(dá)式模式,用JavaScript正則表達(dá)式的形式匹配字符串
exact:string
精確匹配模式,精確匹配整個(gè)字符串,不能用通配符
在沒有指定字符串匹配前序的時(shí)候,selenium 默認(rèn)使用golb 匹配模式
3.Select Option Specifiers (Select選項(xiàng)指定器)
label=labelPattern
通過匹配選項(xiàng)中的文本指定選項(xiàng)
例如:label=regexp:^[Oo]ther
value=valuePattern
通過匹配選項(xiàng)中的值指定選項(xiàng)
例如:value=other
id=id
通過匹配選項(xiàng)的id指定選項(xiàng)
例如: id=option1
index=index
通過匹配選項(xiàng)的序號(hào)指定選項(xiàng),序號(hào)從0開始
例如:index=2
在沒有選項(xiàng)選擇前序的情況下,默認(rèn)是匹配選項(xiàng)的文本