Advanced Web UI Components Automation with WebDriver C#

Advanced Web UI Components Automation with WebDriver C#

Most of the websites out there use commercial Web UI Components for their front end.  Most of these components are JavaScript-based, and their test automation is a little bit trickier. In this article, I am going to show you how you can automate such controls using their JavaScript API. For the examples, I am going to use the WebDriver. However, you can easily apply the same principles for any other web automation framework.

Automate Kendo DatePicker

Kendo DatePicker

Here we will create a custom HTML control again wrapping the JavaScript API of the component. Compared to the previous example, the only difference is that the constructor accepts an ID.

Custom Control’s Code

namespace AdvancedWebUiComponentsAutomation;

public class KendoDatePicker
{
    private readonly string _idLocator;
    private readonly IWebDriver _driver;

    public KendoDatePicker(IWebDriver driver, string idLocator)
    {
        _driver = driver;
        _idLocator = idLocator;
    }

    public void SetDate(DateTime dateTime)
    {
        string scriptToBeExecuted = string.Format("$('#{0}').kendoDatePicker({{ value: new Date({1}, {2}, {3}) }});", _idLocator, dateTime.Year, dateTime.Month - 1, dateTime.Day);
        var javaScriptExecutor = (IJavaScriptExecutor)_driver;
        javaScriptExecutor.ExecuteScript(scriptToBeExecuted);
    }
}

Notice that we use the new C# 10.0 syntax for declaring namespaces where we don’t need to add additional set of { };

Usage in Tests


public void SetDateKendoDatePickerCustomControl()
{
    _driver.Navigate().GoToUrl("http://demos.telerik.com/kendo-ui/datepicker/index");
    var datePicket = new KendoDatePicker(_driver, "datepicker");
    datePicket.SetDate(DateTime.Now);
}

Automate Gauge Needle

Gauge Needle

We want to move the arrow to a specific number.

Custom Control’s Code

namespace AdvancedWebUiComponentsAutomation;

public class GaugeNeedle
{
    private readonly string _idLocator;
    private readonly IWebDriver _driver;

    public GaugeNeedle(IWebDriver driver, string idLocator)
    {
        _driver = driver;
        _idLocator = idLocator;
    }

    public void SetValue(int value)
    {
        string scriptToBeExecuted = string.Format("$('#{0}').igRadialGauge('option', 'value', '{1}');", _idLocator, value);
        var javaScriptExecutor = (IJavaScriptExecutor)_driver;
        javaScriptExecutor.ExecuteScript(scriptToBeExecuted);
    }
}

Usage in Tests


public void SetValueGaugeNeedleCustomControl()
{
    _driver.Navigate().GoToUrl("http://www.igniteui.com/radial-gauge/gauge-needle");
    var gaugeNeedle = new GaugeNeedle(_driver, "radialgauge");
    gaugeNeedle.SetValue(44);
}

Automate FullCalendar

http://fullcalendar.io/

FullCalendar is a drag-n-drop jQuery plugin for displaying events on a full-sized calendar. It is a JavaScript event calendar, customizable and open source.

Custom Control’s Code

namespace AdvancedWebUIComponentsAutomation;

public class FullCalendar
{
    private readonly string _fullCalendarMethodJqueryExpression = "$('#{0}').fullCalendar('{1}')";
    private readonly string _idLocator;
    private readonly IWebDriver _driver;
    public FullCalendar(IWebDriver driver, string idLocator)
    {
        _driver = driver;
        _idLocator = idLocator;
    }
    public void ClickNextButton()
    {
        string scriptToBeExecuted = string.Format(_fullCalendarMethodJqueryExpression, _idLocator, "next");
        var javaScriptExecutor = (IJavaScriptExecutor)_driver;
        javaScriptExecutor.ExecuteScript(scriptToBeExecuted);
    }
    public void ClickPreviousButton()
    {
        string scriptToBeExecuted = string.Format(_fullCalendarMethodJqueryExpression, _idLocator, "prev");
        var javaScriptExecutor = (IJavaScriptExecutor)_driver;
        javaScriptExecutor.ExecuteScript(scriptToBeExecuted);
    }
    public void GoToToday()
    {
        string scriptToBeExecuted = string.Format(_fullCalendarMethodJqueryExpression, _idLocator, "today");
        var javaScriptExecutor = (IJavaScriptExecutor)_driver;
        javaScriptExecutor.ExecuteScript(scriptToBeExecuted); ;
    }
    public void GoToDate(DateTime date)
    {
        string scriptToBeExecuted = string.Format("$('#{0}').fullCalendar('gotoDate', $.fullCalendar.moment('{1}-{2}-{3}'))", _idLocator, date.Year, date.Month - 1, date.Day);
        var javaScriptExecutor = (IJavaScriptExecutor)_driver;
        javaScriptExecutor.ExecuteScript(scriptToBeExecuted);
    }
}

FullCalendar is a drag-n-drop jQuery plugin for displaying events on a full-sized calendar. It is a JavaScript event calendar, customizable and open source

Usage in Tests


public void TestMethodsFullCalendarCustomControl()
{
    _driver.Navigate().GoToUrl("https://fullcalendar.io/docs/v3/month-view-demo");
    var fullCalendar = new FullCalendar(_driver, "calendar");
    fullCalendar.ClickNextButton();
    fullCalendar.ClickPreviousButton();
    fullCalendar.GoToDate(new DateTime(2012, 11, 28));
    fullCalendar.GoToToday();
}

Automate Kendo ColorPicker

Kendo ColorPicker

Custom Control’s Code

namespace AdvancedWebUiComponentsAutomation;

public class KendoColorPicker
{
    private readonly string _colorPickerSetColorExpression = "$('#{0}').data('kendoColorPicker').value('#{1}');";
    private readonly string _idLocator;
    private readonly IWebDriver _driver;
    public KendoColorPicker(IWebDriver driver, string idLocator)
    {
        _driver = driver;
        _idLocator = idLocator;
    }
    public void SetColor(string hexValue)
    {
        string scriptToBeExecuted = string.Format(_colorPickerSetColorExpression, _idLocator, hexValue);
        var javaScriptExecutor = (IJavaScriptExecutor)_driver;
        javaScriptExecutor.ExecuteScript(scriptToBeExecuted);
    }
}

Usage In Tests


public void SetColorKendoColorPickerCustomControl()
{
    _driver.Navigate().GoToUrl("http://demos.telerik.com/kendo-ui/colorpicker/index");
    var kendoColorPicker = new KendoColorPicker(_driver, "picker");
    kendoColorPicker.SetColor("ccc");
}

Download full source code

Related Articles

Web Automation

Most Complete Selenium WebDriver 4.0 Overview

In this article part of the WebDriver Series, we will look at the new exciting features and improvements coming in the new version of Selenium WebDriver 4.0. We

Most Complete Selenium WebDriver 4.0 Overview

Web Automation

10 Advanced WebDriver Tips and Tricks Part 3

As you probably know I am developing a series posts called- Pragmatic Automation with WebDriver. They consist of tons of practical information how to start writ

10 Advanced WebDriver Tips and Tricks Part 3

Specflow, Web Automation

Mixing Specflow with Behaviours Design Pattern

The primary goal of the below tests is going to be to purchase different items from the online store. They need to make sure that the correct pric

Mixing Specflow with Behaviours Design Pattern

Web Automation

Design Grid Control Automated Tests Part 1

Once upon a time, I showed you how you can automate complex custom-tuned controls like a grid. You can read about it in my article Automate Telerik Kendo Grid w

Design Grid Control Automated Tests Part 1

Web Automation

Design Grid Control Automated Tests Part 2

In my previous article Design Grid Control Automated Tests Part 1 I started this mini-series about writing decent grid control's automated tests. In this second

Design Grid Control Automated Tests Part 2

Specflow, Web Automation

Advanced SpecFlow: 4 Ways for Handling Parameters Properly

As you can see the type seconds binding doesn't contain anything special about these inputs. All of the magic is happening in the StepArgumentTransformation ste

Advanced SpecFlow: 4 Ways for Handling Parameters Properly
Anton Angelov

About the author

Anton Angelov is Managing Director, Co-Founder, and Chief Test Automation Architect at Automate The Planet — a boutique consulting firm specializing in AI-augmented test automation strategy, implementation, and enablement. He is the creator of BELLATRIX, a cross-platform framework for web, mobile, desktop, and API testing, and the author of 8 bestselling books on test automation. A speaker at 60+ international conferences and researcher in AI-driven testing and LLM-based automation, he has been recognized as QA of the Decade and Webit Changemaker 2025.