Getting the selected item from a drop down list

In Selenium IDE you could simply use getSelectedLabel | locator and that was your currently selected item in the drop down list. Its a bit more of a roundabout way with WedDriver as you can see from the method I have written below: [code] using OpenQA.Selenium; using OpenQA.Selenium.Support.PageObjects; // … public string getSelectedLabel(ddlDropListID) { string […]

Switching Frames in WebDriver

In WebDriver there is no direct replacement of the Selenium IDE command selectFrame, however there is a fairly straightforward approximation by using the driver.SwitchTo() method. This method allows you to change the focus to different windows, alerts and frames, but we will be focussing on frames in this post. Below are examples on how to […]

Page Object Model

Page Objects are a way to encapsulate the technical details of a web page and the services it provides so that the developer of a test does not need to delve into the structure of the webpage. Essentially the Page Object acts as an interface between the web page and the testing of that page. […]

How to execute JavaScript in your C# tests

In WebDriver you can call javascript functions programatically without having to click on a link with javascript code as the href attribute. This functionality uses the IJavaScriptExecutor interface. This allows you to execute javascript commands on your browser from your Selenium Webdriver test. Here is a short example to get the current URL: [code] IWebDriver […]

How to MouseOver in your C# tests

I have created a fairly simple to use C# method to perform a MouseOver operation, all you need to do is to specify the web element to MouseOver. Add the following using statement first: [code]using OpenQA.Selenium.Interactions;[/code] Then create the following method: [code] public static void MouseOver(IWebElement theElement) { Actions builder = new Actions(driver); builder.MoveToElement(theElement).Build().Perform(); Thread.Sleep(1500); […]

WebDriver 2.43 released

A new version of WebDriver has been released on September 9th. Java: Download – Changelog C#: Download – Changelog The C# NuGet packages have also been update to version 2.43 For further language bindings, documentations and information you can find the link to the Selenium HQ Download page on the Resources page.

Using ChromeDriver Options

There are a number of different ChromeDriver options (and for the other browsers too) that allow us to control how the browser starts up. In this example we see how Chrome is started when no options are selected: Using the following options we can specify that Chrome start without the warning message and that it […]

Importing Config Files with C# NUnit tests

How to use an NUnit Configuaration file to pass values to a test at runtime? Create your XML Configuration file using the format below. Add your Key,Value pairs in appSettings section Use the correct file name for your config file Add a reference to System.Configuration and add a corresponding using statement Use the ConfigurationManager object […]

C# Snippet: Random Number

Here is a useful snippet to generate a six digit random number in C# [code] // Generate a 6 digit random number Random r = new Random() randomNumber = r.Next(100000,999999); Console.WriteLine(“Your random number is: {0}”, randomNumber); // end [/code] Originally posted in /bloggarriv.

Basic C# NUnit Test Setup

This post will outline the basic structure of how to setup your C# NUnit test. First of all here is the code of the basic empty C# NUnit test file. I’ll explain all of the different parts below. [code] namespace MyWebDriverTest { [TestFixture] public class Class1 { [Test] public void TestCase01() { } } } […]