Search This Blog

July 27, 2018

Fixed the issue : jQuery is not defined after upgrading to the new Selenium Driver

Today I upgraded Selenium.Driver and Selenium.Support to v.3.13.1. After running some tests, they failed.  We have the WaitForAjax() method where the first line in C# was as follows:

bool isAjaxDone = ((bool)((IJavaScriptExecutor)_driver).ExecuteScript("return jQuery.active == 0")); 

The interesting part was that this method was created 2 years ago and there was no issue in Selenium 2 and Selenium v.3.11 until I upgraded to v.3.13.1. 

After the upgrade, this line showed the following error directly and ended the test. Using try catch did not work either. 
unknown error: jQuery is not defined 

After updating the code to the following one, the tests pass without any issue. 
bool jQueryDefined = ((bool)((IJavaScriptExecutor)_driver).ExecuteScript("return typeof jQuery != 'undefined'")); 
if (jQueryDefined ) 
{ 
       Other code... 
}    

No comments: