Posts

Showing posts with the label selenium webdriver

C# Selenium code to inject JQuery into wepage

 Below is the sample JQueryUtility class in C# selenium code to verify if jQuery is available on the webpage .If it is not available then inject jQuery into the webpage.      class jQueryUtility     {         private void InjectJqueryIfNeeded()         {             if (!jQueryLoaded())                 InjectJquery();         } //Verify if Jquery is loaded or not.         public Boolean jQueryLoaded()         {             Boolean loaded = false;             IJavaScriptExecutor js = WebDriver as IJavaScriptExecutor;             loaded = (bool)js.ExecuteScript("return window.jQuery ");             return loaded;         } //Inject J...

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("ret...

Execute java script code in Selenium C#

 As we work on automating web pages using selenium , we would stumble up on using java script as a way to fix the clicking on the element or verifying the document ready state to make synchronization to work.  Below are some of the basic example of executing java script in C# selenium web driver.         Browser Title : -            Webdriver.Navigate().GoToUrl("http://www.google.com");             IJavaScriptExecutor js = Webdriver as IJavaScriptExecutor;             string title = (string) js.ExecuteScript("return document.title ");             Console.WriteLine("Title has:{0}",title);        Browser Url :-              Webdriver.Navigate().GoToUrl("http://www.google.com");             IJavaScriptExecutor js = Webdriver as IJavaScriptExec...

C# Selenium WebDriver Wait conditions

Thoughts on WebDriver Wait conditions -  When we are automating a web page ,we quickly come across a situation where we are navigating to a next page and want to access the first web element on the next page or when there is a dependency on two web elements ,some times you need to wait before accessing dependent web element.  In below section we will see how we can handle Wait conditions in Selenium WebDriver. In Selenium WebDriver , there are two different wait conditions. 1)Implicit wait condition 2)Explicit wait condition 1)Implicit wait condition : Implicit wait time is used when you want to configure the webdriver's wait time as a whole for the application under test. Sample code in C#: (highlighted portion in yellow is the code related to wait) Webdriver w ebDriverInstance = new  FirefoxDriver(); WebDriverInstance.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); Assert.AreEqual("Blinds | Window Blinds and Shades | Custom Window...