我正在使用Selenium來驅動使用Dojo的網站。由於網站的Dojo網格使用延遲加載,因此我的測試框架很難知道網格是否完成加載。但是,Selenium確實讓你注入Javascript。有沒有方法可以輪詢DOM,或直接使用js來查找網格是否已完成加載?如何確定dojo網格是否已完成加載?
2
A
回答
0
dojox.grid.DataGrid有獲取_onFetchComplete設置一個內部標誌,所以你可以嘗試
var grid = ...
if (grid._isLoaded) {
...
}
0
我發現這個問題,因爲我一直在尋找同樣的事情。我能得到的最接近的結果是等待Dojo的加載消息消失(如果網格加載速度很快,很難看清楚)。這裏是我現在使用的:
/** Required imports **/
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.By;
/** Code snippet **/
WebDriver driver = new FirefoxDriver();
WebDriverWait wait = new WebDriverWait(driver, /* Max wait time */ 30);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(".dojoxGridLoading"));
這讓我非常接近。
1
這裏是一個偉大的答案,我發現:
grid.connect(grid, '_onFetchComplete', function(){
for(var i in grid._pending_requests){
if(grid._pending_requests[i]){
return; //no, something's not loaded yet.
}
}
//okay, nothing is on the fly now.
});
http://dojo.6188.n7.nabble.com/function-when-the-dataGrid-is-ready-td37563.html
0
這是使用非內部事件 「onStyleRow」 的解決方案:
// Declare myGridLoaded
var myGridLoaded = false;
...
...
// Connect onStyleRow:
dojo.connect(grid, "onStyleRow", grid, function(row) {
if(!myGridLoaded) {
doYourStuff();
// Make sure it runs only once:
myGridLoaded = true;
}
});
// Now set your store and the handler will run only once
// when the first row is styled - if any:
grid.setStore(store);