2012-07-30 57 views
0

我正在使用硒API,並希望編寫一個條件,將斷言如果兩個元素中的任何一個存在。斷言是否存在任何元素?

雖然我看到的唯一選擇是assertElementPresent(定位)單個元素

是否有硒這樣做的一個很好的方式嗎?

回答

1

對於複雜的條件表達式,你可以嘗試使用XPath謂詞從webdriver的API:

def typeToFieldNamed(label: String, value: Any) { 
    val field = webdriver.findElement(By.xpath("(//input|//textarea)[preceding::div[position()=1 and .='" + label + "']]")) 
    field.click() 
    field.sendKeys(chord(CONTROL, HOME)) 
    field.sendKeys(chord(CONTROL, SHIFT, END)) 
    field.sendKeys(value.toString) 
    }