问题
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