The text of element is different from expectation
  • 23 Oct 2023
  • 5 Minutes to read
  • Contributors
  • Dark
    Light

The text of element is different from expectation

  • Dark
    Light

Article Summary

※ Please note that parts of this page are machine translated.

If the text of the target element differs from the expected value in the text assertion step, the test result will display the following message
Text_of_the_element_is_different_from_expectation_EN.png

This "Text of the element is different from expectation" is one of the most common errors.
In this article, we will take an example of a common pattern and explain it. First, check the screenshot of the failed step to see which of the following cases applies.

  1. there is a difference at the step before the failed step compared to the screenshot at the time of recording or the previous successful step (the expected operation was not performed)
  2. the step before the failed step is OK, but the target element is not found in the failed step, or is found but failed.

1. unintended operation in the step before the failed step

Please check whether an unintended element was clicked or a validation error occurred in the form entry in the step prior to the failed step, and take action to ensure that the correct operation is performed.

For example, let's look at an example of an error in step 5 below.
Text_of_the_element_is_different_from_expectation_D_EN.png

First click on the "Check Screenshot" button to see what it looks like in step 5.

Text_of_the_element_is_different_from_expectation_D_step5_JPEN.png

It is true that the character of the target being asserted is different from the previous success, and seems to be different from the expected value.
Next check to see if there was any unintended operation in the step prior to this step 5.
Text_of_the_element_is_different_from_expectation_D_step4_JPEN.png

It seems that the user should have clicked on "English" in Step 4, but for some reason clicked on "Japanese," resulting in the screen being displayed in Japanese, and as a result, the user failed in Step 5.

In this case, it is necessary to check why the user performed a different operation (clicked on the wrong element) in Step 4 instead of Step 5. In this case, Autify AI may have found the wrong element, and a quick element update or re-recording may help.
See also the "Element not found" section "If the target element does not exist on the page" if necessary.

2. The target element has not been found in the failed step, or has been found but failed.

2-1. When the target element of the assertion looks fine on the appearance when looking at the screenshot of the test result, but it has failed

If you look at the error message, the result value is in a blank (no value) state.
Text_of_the_element_is_different_from_expectation_E_EN.png

Then click on the "View Screenshot" button to see what it looks like in step 2.

Text_of_the_element_is_different_from_expectation_E_step2_JPEN.png

Looking at the screenshot of the test results, the element seems to be found without any problem and there seems to be no problem with the screen.
In this case, the target element may be a non-text element (e.g., an image element). Since text assertions are intended for text, they cannot be validated using this assertion command.
Visual regression testing for elements or Assertions on elements in a page.

2-2. When a line break is included in the target element in the difference comparison under the error message

Looking at the error message, text other than line breaks seems to be OK.
On the other hand, the expected value specifies "\n" for "line breaks", but the resulting value is "↵".
Text_of_the_element_is_different_from_expectation_B_EN.png

This may be due to a difference in the handling of line breaks.
In this case, specify the value to be included in the expected value with a line break expression (i.e., a line breaks is formed by pressing the Enter key).

Example: If a line break is expressed with a line break symbol
Text_of_the_element_is_different_from_expectation_enter1_EN.png

Example: if a line break is represented by the enter key.
Text_of_the_element_is_different_from_expectation_enter2_EN.png

Supplement

The treatment of "line breaks" may differ depending on the browser used to execute the file.
Example: In Firefox browser, if a line break is included in the expected value, it fails, but in other browsers, it succeeds if there is a line break.

2-3. The target element is a calendar date value whose value is different from the expected value and the difference is 9 hours or 1 day

The error message indicates that the difference between the expected value and the resultant value is 9 hours or 1 day, and the test fails.
Text_of_the_element_is_different_from_expectation_C_EN.png

If you can identify the target element in the screenshot of the test results, it may be affected by the time zone.
Autify's It adopts Coordinated Universal Time (UTC) as a rule.
Therefore, please consider the following

  • Specify the expected value considering that the test is executed in UTC, instead of the expected value assuming Japan time (JST).

2-4. When looking at the screenshot of the test results, the target element exists, but another element is asserted

For the following example, if you look at the screenshot screen of the failed step, you can see that the same element is asserted as it was during recording (the previous successful step).
However, what we really wanted to verify was the assertion of the date and time of the top line.

Text_of_the_element_is_different_from_expectation_A_EN.png

In this case, if you want to ensure that the intended element is the top, nth, bottom, etc., use the locator to specify the element to be targeted.
For specific instructions, see How do I interact with the elements in a table or list the way I intended?.

In addition to the above examples, if you think Autify may have found the wrong element, please refer to the "Target element not found" section "If the target element exists on the page but has not been found" as necessary.

2-5. When an email is opened differently than expected in the email test step

For the following example, the subject line seems to indicate that the user is opening a different email than when recording.
Text_of_the_element_is_different_from_expectation_mail_EN.png

One possible cause of this is that another email was opened before the target email was received, and an assertion was made about the non-target email.
If it is possible that the next step is being taken before the reception is complete, please add a Sleep step before the target step.
Waiting for the email to be received before asserting may be successful.

For more information on the case where the mail function is not received and the specification of mail search, please also refer to the "In case mail is not received" and "About the specification of mail search for validation target" items in Mail Test as necessary.

If you are still having trouble...

Please contact us. We will work with you to resolve the issue.


Was this article helpful?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.