在我的應用程序中,我有兩個<select>
標籤。第一個更改第二個選項中的選項,並在onchange事件中啓用它。Selenium2的選擇對象不會在IE8中觸發onchange事件
當我使用Selenium2提供的Select對象時,它不會在IE8中運行時觸發該事件(在FF中工作良好,而且手動執行時)。
Select select = new Select(getElementByName(name));
element.selectByValue(value);
第一個<select>
按預期變化。但是,第二個<select>
保持空白並被禁用。我試過這個作爲解決方法:
if(ie) {
WebElement select = getElementByName(name);
WebElement option = select.findElement(By.cssSelector("[value='"+value+"']"));
List<WebElement> options = select.findElements(By.cssSelector("option"));
//select the first element
options.get(0).click();
//make sure the select is focused
select.click(); //open
select.click(); //close
Keyboard keyboard = getWebDriver().getKeyboard();
for(int i = 0; i < options.size() && option.getAttribute("selected") == null; i++) {
keyboard.pressKey(Keys.DOWN);
//note: if i do a Thread.sleep(100); here, it works more consistently, but still not 100%
}
} else {
// Do the above snippet
}
但現在我得到不一致的結果。所需的<option>
總是被選中,而有時只有事件被觸發。
很明顯,最好的選擇是讓選擇在IE8中工作。有其他人看過這個問題嗎?看起來像Selenium2中的一個錯誤。有沒有已知的解決方法?
我都沒有這個確切的問題,但我有問題,其中硒工作的最時間,但有時由於該元素尚未出現在頁面上而大部分時間都會失敗。我寫了一個方法,等待元素加載,然後再試一次。如果再次失敗,我會自動重新測試失敗。不是最佳的,但它的工作原理。 –