Selecting Elements with Context and Content Commands

Overview

When building tests, especially those involving tables or forms, you often need to interact with generic elements like checkboxes, input fields, or buttons. Context and Content commands in the Element Miner provide a powerful way to locate these elements by using nearby or internal text as a reliable anchor, even when the data is dynamic.

How It Works

The best way to decide which command to use is to ask: "Is the text I'm looking for inside the target element, or just near it?"

Context Commands (Look "Near" the Target)

Use these commands when the target element itself is generic (like a checkbox, radio button, or empty text field) but is positioned next to a unique, visible label or text. The system uses this text as an anchor to find the target element.

  • row_context("unique_text_in_row"): This is ideal for tables. It finds the specified text on the screen and creates a horizontal "search zone" across that specific row to locate the target element.
  • context("label_text"): Finds an input field or other element located near the specified label text.
  • tabular_context("Total", 2, false): Selects a cell based on its grid coordinates relative to headers or other cells.

Content Commands (Look "Inside" the Target)

Use these commands when the unique text is part of the button, link, or element you want to interact with.

  • content("Submit"): Finds the button or element that contains the text "Submit". This is generally preferred over attribute(TV=...) because it searches deeper into the element's structure.
  • content(TV?"Part"): Use the ? operator for partial matches if the text has dynamic parts or extra spaces.
  • content(TV*="regex"): Use the * operator for complex patterns, such as matching specific date formats or Order IDs.

Best Practices

The "Gold Standard" for Tables

For handling dynamic tables or grids, the most resilient approach is to combine row_context with an attribute selector. This method first isolates the correct row using visible text and then pinpoints the exact element within that row.

For example, to click a checkbox in a row identified by a template name:

row_context("{{fze.local.templateName}}")
attribute(TN="INPUT")
clear_hidden()
  1. row_context("{{fze.local.templateName}}"): Uses a variable holding a visible template name to give the model a real-time visual anchor. It finds this text and confines the search to that specific row.
  2. attribute(TN="INPUT"): Provides precision. It tells the model, "Within the correct row, click the element that is an INPUT tag (the checkbox)."
  3. clear_hidden(): This is an optional but recommended command that optimizes performance on large pages by instructing the system to ignore any elements not currently visible in the browser's viewport.

Using Dynamic Variables

When your test generates or uses dynamic data (like a new user email or a transaction ID), always reference it using the double curly brace syntax {{fze.local.VariableName}}.

  • To click the element containing the new data: content("{{fze.local.VariableName}}")
  • To click a checkbox or button next to the new data: row_context("{{fze.local.VariableName}}")

Limitations

The primary limitation arises when a context command is used with text that is not visibly present on the page. For example, using context("some_invisible_ID") forces the system to fall back on Historical Mapping, where it tries to remember where the element was during the initial test recording. This is less reliable than using a visible anchor. For robust and resilient tests, always use a visible text label or value as the anchor for any context or row_context command.