2011-07-03 147 views
0

如何選擇使用硒代碼爲Firefox的Ajax下拉建議列表項目?使用Selenium for Firefox選擇Ajax下拉建議列表

我的問題是:Ajax下拉列表是可見的,但它沒有被選中,接下來的步驟卡住了。 可能是硒正在等待什麼。

頁面填充的列表是動態的,並且位於bla bla標記中。 請幫助一個示例代碼。 我如何在這裏使用waitfor *。 記得我沒有使用Firefox,但我正在編寫代碼。 請幫忙。

回答

0

我在與你的問題有點困惑「:Ajax的下拉列表中可見,但它沒有選擇」

這聽起來像該元素將被禁用。 (Java編碼)

若然selenium.isElementDisabled()

如果不是的話,

1)使用編程laguage溶液中,同時循環並isElementPresent() OR isElementDisabled()

//trigger the Ajax request and then 
long initialTime = System.currentTimeMillis(); 

do{ 
    thread.sleep(1000); 
}while((!selenium.isElementPresent("AjaxElement")) && (System.getCurrentTimeMillis() - initialTime <= 5000)) ; 

//一些事像上文針對客戶端編程解決方案...但是,

2)硒的內置解決方案

我們有一個方法叫waitForCondition("java script to be executed", "time out value"); 這種方法循環的JavaScript語句,直到它返回true或出現供應超時

這裏最重要的是分析應用/阿賈克斯元素找出的這些特定條件元素更改。

從explation我的猜測是這樣的,display=none將改爲display=block OR disabled=true將改爲disabled=false OR isReadOnly將改爲沒有這樣的屬性ECT .....(你需要弄清楚這一點)

,然後用這個attribute = value建立一個javascript功能,

selenium.waitForCondition("window.document.getElementById('AJAX ELEMENT').disabled == 'false'", "3000"); 

你可以工作,但上述聲明你想在你的編程語言。

try { 
//do the action which triggers the Ajax call 
    selenium.waitForCondition("window.document.getElementById('AJAX ELEMENT[drop down element]').disabled == 'false'", "3000"); 
//OR 
    selenium.waitForCondition("window.document.getElementById('AJAX ELEMENT').disabled == 'false'", "3000"); 
} 
catch(SeleniumException se) 
{ 
    if((se.getMessage()).toLowerCase().contains("timed out") 
    throw //..some a custom exception however your organisation requires 
} 
selenium.select("drop down element id", "option id"); 

等等.....

相關問題