Documentation Index

Fetch the complete documentation index at: https://helpcenter.autify.com/llms.txt

Use this file to discover all available pages before exploring further.

Causes and solutions for the "strict mode violation" error

Prev Next

This article explains the causes and solutions for the "strict mode violation" error that occurs during test execution.

Overview

When you run a test in Autify Nexus, a step may fail, and the following message may appear in the error details.

strict mode violation: getByText('element name', { exact: true }) resolved to 2 elements

Causes

This error means that the locator (the condition for finding an element) specified for the operation matched multiple elements on the screen. Due to the specification (strict mode) designed to prevent unintended operations on the wrong element, it is treated as an error if it cannot be narrowed down to a single element.

Common conditions for occurrence

  • There are multiple elements with the same text on the screen (e.g., table headings and row data, menu items with the same name, etc.).

  • The previous test execution failed halfway, and the created data remains on the screen without being deleted.

Solutions

To resolve the error, take one of the following actions.

Solution 1: Clean up data in the test environment

If the cause is that data created in the previous test remains, organize the environment.

  1. Open the target screen for the test and visually check if the target data is displayed in duplicate.

  2. If it is duplicated, manually delete the data and run the test again.

  3. As a future countermeasure, we recommend adding a preprocessing step at the beginning of the scenario to "delete target data if it remains."

Solution 2: Change to a more unique locator (For normal steps)

On screens where multiple elements with the same text may exist, change to a unique locator that does not rely solely on text.

  1. On the scenario edit screen, open the target step where the error occurred.

  2. Open Advanced settings and click Change locator.

  3. Enter the new locator in the Locator field.

  4. Click Done to save.

Solution 3: Make it unique on the code side (For "Playwright Code" steps)

If there is a possibility of multiple matches with getByText or getByRole, modify the code to specify a single element.

  • Filter by a parent element or container.

  • Filter using filter({ hasText: '...' }).

  • Utilize stable attributes such as getByTestId.

If not resolved

If the error persists after trying the steps above, please contact our support team.