TestProject Forum

How to verify that an element text is a part of a text in parameter

Hi I am trying to verify an element text (that I am retrieving by Get text action) is part of a text (that I saved as a parameter).
For example an element text randomly display on web site like ‘One’ or sometime ‘Two’ etc., I want to make sure this is part of already defined list in a parameter like 'One, Two, Three, Four, Five).

Appreciate any help.

Hi @qaisar.ahmed .

To achieve that, you can do something like this:

  • First, create a parameter and add as value the defined list you mentioned. Let’s call it “List_parameter” :

please make sure you used the key " | " to separate the values, and not comma .

  • Then, lets get the text we want to validate using the action “Get text”:

And add a RegEx validation:

Let me know if you managed :slight_smile:

Hi @Ricardo.Caster

Great, thanks for your reply. Look like the original problem mentioned in this post is resolved. Could you please guide me where I can learn more about TestProject RegEx feature?

I will appreciate if you please help me to find the solution for scenario I am trying to test.

For example, a web element displays randomly displays one of 20 possible values. If the text is long then on web element text shortened with …

Text shortening example 1: How to make better decisions under…
Text shortening example 1: How to make better decisions und…

Actual Text: How to make better decisions under stress with Dr ABC

I saved actual text in a parameter. Now when I get element text and try to compare, the step fail. Problem is I cannot save shortened form text in parameter as this list is 200+ items and continually growing, also there is no fix rule to shortened the title as this also depends on screen size.


Happy to know, @qaisar.ahmed .

Regarding the RegEx, I can suggest you a great video that explain how can you build RegEx.
Then, you can simply add it to your tests like in the example I sent before or using some of our actions that uses RegEx. You can see them in the Community Addon “String Utils”. Some of the actions are: “Extract String using RegEx” , “Replace substrings with regex” , and more.
Here is the video I mentioned: Regular Expressions - Enough to be Dangerous - YouTube

Regarding your last query, can you please give more details about it? You said it can be 20 possible values, but are all of them a short view of this specific full text: “How to make better decisions under stress with Dr ABC”? Maybe taking a screenshot would be helpful and, if possible, also sharing the website here or using the chat. I’d be happy to assist :slight_smile:

Hi @Ricardo.Caster

Thank you very much, this RegEx related video is very helpful. Regarding my query, some possible values is shortened by placing 3 dots (…) at the end, and some are small enough that no need to short.

In parameter, I put the longer values as in shortened form, so everything was looking fine. Then I came across another problem, that some of the possible values also contains pipe sign ‘|’ symbol. RegEx consider this one value as 2, and step get fail. Please see screen shot below.
Is there a way we can ignore this pipe sign value in RegEx for some values, please?

Hi @qaisar.ahmed .

You can remove the"|" symbol. To achieve that, you can store the whole text into a parameter using the action “Get text”, then add a new step that removes the “|” using the action “Replace substrings”, like this:

Hi @Ricardo.Caster

Great. Yes this worked for me. Thank you very much. You guys are doing great.

Thanks, @qaisar.ahmed .

Happy to help :slight_smile:
If you have any further questions let us know.

This topic was automatically closed after 46 days. New replies are no longer allowed.