What Custom WebElement Wrappers Does Ocaramba Provide?

Ocaramba provides strongly-typed custom WebElement wrappers—including Table, Select, Checkbox, and extensible base classes—that inherit from a core WebElement base to expose domain-specific actions while maintaining full access to underlying Selenium IWebElement functionality.

The accenture/ocaramba framework simplifies Selenium WebDriver automation by offering a set of custom WebElement wrappers that abstract common UI interactions. These wrappers extend the base WebElement class to provide specialized methods for handling tables, dropdowns, and checkboxes, enabling cleaner test code that operates on higher-level components rather than raw Selenium elements.

Overview of Ocaramba's Custom WebElement Wrapper Architecture

Ocaramba's custom WebElement wrappers are discovered through the generic GetElement<T>() extension method defined in SearchContextExtensions.cs. When you request an element as a specific wrapper type, Ocaramba automatically constructs the wrapper by passing the raw IWebElement to the wrapper's constructor. This design preserves full access to underlying Selenium functionality while adding domain-specific convenience methods.

Built-in Custom WebElement Wrappers in Ocaramba

The framework ships with four primary wrapper implementations located in the OcarambaLite/WebElements/ directory, plus a sample extension demonstrating custom implementation patterns.

Table Wrapper for HTML Tables (OcarambaLite/WebElements/Table.cs)

The Table wrapper represents HTML <table> elements and provides methods to extract tabular data into usable C# structures. The primary method GetTable(ElementLocator rowLocator, ElementLocator columnLocator) returns the table contents as a two-dimensional string array, enabling data-driven assertions against grid contents without manual iteration logic.

Select Wrapper for Dropdown Controls (OcarambaLite/WebElements/Select.cs)

The Select wrapper provides a strongly-typed façade over Selenium's SelectElement for handling <select> dropdowns. Key methods include:

  • SelectElement() – Returns the underlying Selenium SelectElement
  • SelectByText(string) / SelectByIndex(int) / SelectByValue(string) – Option selection methods
  • IsSelectOptionAvailable(string) – Verifies option existence before selection

Checkbox Wrapper for Toggle Inputs (OcarambaLite/WebElements/Checkbox.cs)

The Checkbox wrapper simplifies interactions with <input type="checkbox"> elements through explicit state management methods:

  • Check() – Ensures the checkbox is selected
  • Uncheck() – Ensures the checkbox is deselected
  • IsChecked (property) – Returns the current boolean state

CustomGrid Sample for Extending Ocaramba (Ocaramba.Tests.PageObjects/CustomGrid.cs)

The CustomGrid class in the test project demonstrates how to implement user-defined wrappers. Located at Ocaramba.Tests.PageObjects/CustomGrid.cs, this sample stores the wrapped IWebElement and implements domain-specific logic such as IsGridDisplayed(), which returns webElement.Displayed. This pattern serves as a template for teams needing specialized element types beyond the built-in set.

How to Use Ocaramba Custom WebElement Wrappers in Your Tests

To utilize these wrappers, invoke the generic GetElement<T>() method with the desired wrapper type and an ElementLocator. The following examples demonstrate practical usage patterns.

Retrieve a dropdown and select an option by visible text:

var colourSelect = driver.GetElement<Select>(Locator.Id("color"));
colourSelect.SelectByText("Red");

Extract table data into a string matrix for validation:

var ordersTable = driver.GetElement<Table>(Locator.Css("table.orders"));
string[][] data = ordersTable.GetTable(
    Locator.Css("tr"),          // rows selector
    Locator.Css("td"));         // columns selector

Toggle a checkbox based on its current state:

var termsCheckbox = driver.GetElement<Checkbox>(Locator.Name("terms"));
if (!termsCheckbox.IsChecked) {
    termsCheckbox.Check();
}

Implement a user-defined wrapper for custom grid logic:

var grid = driver.GetElement<CustomGrid>(Locator.Css(".grid"));
bool visible = grid.IsGridDisplayed();   // custom logic defined by the user

Summary

Frequently Asked Questions

What is the base class for Ocaramba custom WebElement wrappers?

All custom WebElement wrappers in Ocaramba inherit from the WebElement base class defined in the framework's core. This base class encapsulates the underlying Selenium IWebElement and provides common functionality, allowing derived wrappers to focus on domain-specific behaviors while maintaining access to standard Selenium methods.

How does Ocaramba instantiate custom wrapper classes?

Ocaramba instantiates custom wrappers through the generic GetElement<T>() extension method located in SearchContextExtensions.cs. When you call driver.GetElement<Select>(locator), the framework locates the element using the provided locator, then constructs an instance of the requested wrapper type by passing the raw IWebElement to the wrapper's constructor.

Can I create my own custom WebElement wrappers in Ocaramba?

Yes, you can create custom WebElement wrappers by inheriting from the WebElement base class and implementing domain-specific methods. The CustomGrid class in Ocaramba.Tests.PageObjects/CustomGrid.cs serves as a reference implementation, demonstrating how to store the wrapped element and add custom logic such as IsGridDisplayed() while maintaining compatibility with the GetElement<T>() instantiation mechanism.

Where are the built-in wrapper classes located in the Ocaramba repository?

The built-in custom WebElement wrappers are located in the OcarambaLite/WebElements/ directory. Specifically, you will find Table.cs for table interactions, Select.cs for dropdown handling, and Checkbox.cs for checkbox controls. The sample custom wrapper CustomGrid.cs resides in the test project at Ocaramba.Tests.PageObjects/CustomGrid.cs.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →