Part 2 series of calling java script code in C# Selenium


Part 2 series of calling java script code in C# Selenium .Below sample code is helpful in synchronization of page loads with Explicit Wait conditions.

          

              Document Ready State :-

            Webdriver.Navigate().GoToUrl("http://www.google.com");
            IJavaScriptExecutor js = Webdriver as IJavaScriptExecutor;
            string readyState = (string) js.ExecuteScript("return document.readyState");
            Console.WriteLine("Ready State is {0}",readyState);

            Verify if Jquery is available on the webpage :-

            IJavaScriptExecutor js = Webdriver as IJavaScriptExecutor;

            jQueryNotLoaded = (bool)js.ExecuteScript("return typeof jQuery == 'undefined' ");
            
            jQueryNotLoaded is true when jquery is not used on the webpage .
             
           (or)

             IJavaScriptExecutor js = Webdriver as IJavaScriptExecutor;

            jQueryLoaded = (bool)js.ExecuteScript("return window.jQuery ");
           
           jQueryLoaded is true when jquery is available on the webpage.

           Verify if JQuery has completed all Ajax calls
            
            IJavaScriptExecutor js = Webdriver as IJavaScriptExecutor;

            jQueryNotLoaded = (bool)js.ExecuteScript("return jQuery.active == 0 ");

Comments

Post a Comment

Popular posts from this blog

Why we need to test the website on different browsers ?

Information on Code Analysis tool

Master degree (CS) VS Job