Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to find out if jqGrid is loaded and ready with Selenium

How are you finding out if jqGrid is loaded and ready to be used, via selenium.

Some details :

  • Im using C# driver
  • I have a method : new WebDriverWait(driver, new TimeSpan(0, 0, 0, 30)).Until(x => loadingdissapearedcondition) which im using to wait until Loading.. element is gone.
  • I also sometimes use this script :

private const string script = @"return ($('#{0}').jqGrid('getGridParam', 'reccount') !=x undefined) && ($('#{0}').jqGrid('getGridParam', 'reccount') != 0) && (!$('#load_{0}').is(':visible')) && (!$('#busyIcon').is(':visible'))";

private readonly string waitScript;

waitScript = string.Format(script, jqGridId);

public void WaitUntilLoadIconDissappears()
{
    driver.WaitUntil(MAXWAIT, Wait);
}

public bool Wait()
{
    var executeScript = ((IJavaScriptExecutor) driver).ExecuteScript(waitScript);
    bool result;
    bool tryParse = bool.TryParse(executeScript.SafeToString(), out result);
    return tryParse && result;
}

to find if jqGrid has records and loading done.

I require something better - as even the above two does not make driver wait until load finishes, if we are using local data for jqGrid. Im also curious what is the best way, or at the minimum, how others are dealing with this problem.

like image 273
Zasz Avatar asked Dec 12 '22 23:12

Zasz


1 Answers

I never used Selenium before, so I'm not sure that I understood your problem correctly. jqGrid will be first initialized and then (optionally) the data can be loaded from the server. During the initializing stage the original <table id="grid"></table> element will be converted to relatively complex HTML fragment which is the grid. At the end of the initialization the DOM element of the table (the $("#grid")[0]) will get the expando grid.

So you can use the test like

if ($("#grid")[0].grid) {
    // grid is initialized
}

to determine that the grid is already initialized. jqGrid uses the same test internally (see here for example).

like image 97
Oleg Avatar answered Dec 22 '22 04:12

Oleg