Month: <span>December 2012</span>

Basic WebDriver and C# script for beginners

WebDriver Test using C# and Visual Studio 2013 Express. One of my videos is getting multiple hits for how to write WebDriver or selenium tests using C#. There are many tutorials available on the internet for Java but not many for WebDriver and C#. I will teach you how to write test scenario in C#. I have Visual Studio 2013 express edition. Step1: Create WebDriver Project Create new Project, and choose ‘Unit Test Project’, and give some name says; ‘AddItemToShoppingCart’ and hit the OK button. You will see following folder structure and if you open UnitTest1.cs, you will see the …

How to use WebDriver to handle dropdown or select tag

We can use regular webdriver command to handle most of webelements like check box, text box etc. but to handle dropdown or select element as given below [sourcecode language=”htm”] <select id="sel123"> <option value="my">My</option> <option value="name">Name</option> <option value="is">Is</option> <option value="admin">Admin</option> </select> [/sourcecode] you can use following code. [sourcecode language=”csharp”] IWebElement sTag = driver.FindElement(By.Id("sel123")); OpenQA.Selenium.Support.UI.SelectElement selectTag = new OpenQA.Selenium.Support.UI.SelectElement(sTag); selectTag.SelectByValue("admin"); //Or selectTag.SelectByText("Admin"); //Or selectTag.SelectByIndex(3); [/sourcecode] In case if you want to verify how many options are available in select tag then use following: [sourcecode language=”csharp”] var availableOptions = selectTag.Options; foreach (IWebElement item in availableOptions) { Console.WriteLine(item.Text); } [/sourcecode]