How to determine if a dojo grid has finished loading?

◇◆丶佛笑我妖孽 提交于 2019-12-22 17:51:26

问题


I'm working with Selenium to drive a site that uses Dojo. Since the site's Dojo grid uses lazy loading, it's difficult for my test framework to know if/when the grid has finished loading. However, Selenium does let you inject Javascript. Is there a way to either poll the DOM, or use js directly, to find out if a grid has finished loading?


回答1:


Here is a great answer that I found:

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




回答2:


dojox.grid.DataGrid has an internal flag that gets set in _onFetchComplete, so you could try

var grid = ...
if (grid._isLoaded) {
    ...
}



回答3:


I found this question because I was looking for the same thing. The closest I can get is to wait for Dojo's Loading Message to disappear (if the grid loads fast, it's hard to see). Here is what I use right now:

/** 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"));

This gets me really close.




回答4:


This is a solution using non-internal event "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);


来源:https://stackoverflow.com/questions/9619941/how-to-determine-if-a-dojo-grid-has-finished-loading

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!