In order to improve the selenium waits on my website I need to check whether a particular table has finished drawing.
The site I am looking at uses datatables.net, it provides both pre and post draw event handlers.
My javascript code looks like the following...
var isDrawn;
var table = $("#CustomField-443c6726-05c3-48d0-8dfe-c1a26d749cdf").DataTable();
table.on('preDraw', function () {
console.log('Redraw started at: ' + new Date().getTime());
isDrawn = false;
});
table.on('draw', function () {
console.log('Redraw finished at: ' + new Date().getTime());
isDrawn = true;
});
function returnDrawStatus() {
console.log(isDrawn);
return isDrawn;
};
If I paste this into the console window in chrome dev tools, it seems the event handlers are attached, and I can access the 'isDrawn' variable and the 'returnDrawStatus()' function.
When I try to do the same thing using the selenium javascript executor, the event handlers are attached (evidenced by the console log messages if I pause my selenium script and reorder the table), but I can't return the value of 'IsDrawn' as I get the following error..
System.InvalidOperationException occurred
HResult=0x80131509
Message=unknown error: returnDrawStatus is not defined
This is the method that executes the javascript, with the value of script string variable being returnDrawStatus();
internal static bool ExecuteJavascriptReturn(IWebDriver driver, string script)
{
var result = ((IJavaScriptExecutor) driver).ExecuteScript(script);
return (bool)result;
}
TLDR
Thanks
C# + Selenium WebDriver
((IJavaScriptExecutor)driver).ExecuteScript("window.foo = false;");
User contributions licensed under CC BY-SA 3.0