Selecting Elements by Excluding Attribute Substrings

Overview

When building automated tests, it is often necessary to select elements based on what their attributes do not contain. A common scenario is identifying active or enabled elements by excluding those with a 'disabled' class. While the attribute() command is useful for positive matches, a different approach is needed for negative partial matches (i.e., 'does not contain'). This guide explains how to use the content() command in the Functionize DSL to achieve this.

How It Works

The primary challenge arises when an attribute, like class, contains multiple values. For example, an element might have class="item-class disabled". In this case, using a 'not equals' operator like attribute(CL!="disabled") will not work as intended because the full attribute value is not an exact match to 'disabled'.

The correct way to filter out elements where an attribute contains a specific substring is to use the content() command with the ~? operator.

For example, to find an element where the class attribute does not contain the word 'disabled', use the following syntax:

content(CL~?"disabled")

This command breaks down as follows:

  • content(): The command used to evaluate element attributes or text.
  • CL: The standard abbreviation for the class attribute.
  • ~?: The 'does not contain' operator. It filters out any element where the specified attribute contains the given substring.
  • "disabled": The substring to search for and exclude.

This approach correctly identifies and interacts with elements that are not disabled, even when the class attribute contains other values.

Limitations

The 'does not contain' (~?) operator is available within the content() command but is not currently supported for the attribute() command. Users should always use content() for this specific 'not contains' logic.

Related Information

It is important to distinguish between the 'does not contain' and 'does not equal' operators:

  • content(CL~?"disabled"): Selects elements where the class attribute does not contain the substring 'disabled'.
  • content(TV!="Submit"): Selects elements whose text value is not an exact match to 'Submit'.