Overriding the SendKeys Selenium 2 Webdriver

Here is a function I have written that checks if an element is present and then executes the Type/SendKeys command. public void type(String xpath, String value) { if (driver.FindElement(By.XPath(xpath))!=null) { driver.FindElement(By.XPath(xpath)).SendKeys(value); } else { Console.WriteLine(“The element is not found: ” + xpath); } } Using the function in the test script. type(“//input[@name=’p’]”, “Selenium Wiki”);

How to add proxy setting to webdriver

I had to run the Webdriver scripts on a Firefox and I had to use a particular proxy to get access to the QA/Dev environment. Here is the code that you can use to change the proxy settings. FirefoxProfile firefoxProfile = new FirefoxProfile(); firefoxProfile.setPreference(“network.proxy.type”, 1); firefoxProfile.setPreference(“network.proxy.http”, “”); firefoxProfile.setPreference(“network.proxy.http_port”, 80); firefoxProfile.setPreference(“network.proxy.ssl”, “”); firefoxProfile.setPreference(“network.proxy.ssl_port”, 80); firefoxProfile.setPreference(“network.proxy.no_proxies_on”, “”); […]

Using Selenium IsSomethingSelected

Here is an example of using Selenium IsSomethingSelected. This example is written is Visual Studio C#. try { Assert.IsTrue(selenium.IsSomethingSelected(“ctl00_WebsiteId”)); string selectedLabel = selenium.GetSelectedLabel(“ctl00_WebsiteId”); string selectedItem = selenium.GetSelectedValue(“ctl00_WebsiteId”); Console.WriteLine(selectedLabel); Console.WriteLine(selectedItem); } catch (Exception e) { verificationErrors.Append(e.Message); } If you found this solution helpful or have something extra to add, feel free to share it here by […]

Using Selenium WaitForCondition

In this example I will tell you how you can use selenium WaitForCondition command. Below is the code for waitForElementPresent. You can do the same with WaitForCondition and pass the element id. Here I will waiting for element “//div[@id=’ctl00_contentSection_LoginPanel’]/h2″ then once the element is found continue with testing other things. This is waitForElementPresent code for […]