Site Loader
Auckland, New Zealand
In the last post we discussed how to work with Javascript and how Selenium works under the hood with some of the Javascript which we discussed. In this post we will discuss how to work run those Javascript and mimic the actual behavior of Selenium by executing some of the Javascript using IJavascriptExecutor interface. Here is the complete video discussion on it Here is the code of above video
           string loadingScript = "return document.readyState";

            var state = ExecuteJavaScript(loadingScript);


            while (state.ToString() != "complete")
            {
                System.Threading.Thread.Sleep(3000);
            }

            Console.WriteLine("Loaded");

            //Typing in the textbox
            string textboxScript = "document.getElementById('twotabsearchtextbox').value= 'test'";

            ExecuteJavaScript(textboxScript);

            string clickSearch = "document.getElementsByClassName('nav-input')[0].click();";

            ExecuteJavaScript(clickSearch);

Code for ExecuteJavaScript

       public object ExecuteJavaScript(string script)
        {
            return ((IJavaScriptExecutor)_driver).ExecuteScript(script);
        }

Thanks for reading the post and watching the video!!! Please leave your comments and let me know if there is anything I should update in this post. Thanks, Karthik KK

Post Author: Karthik kk

Leave a Reply

Your email address will not be published. Required fields are marked *