Ask a Question

Comparing 2 numbers contained in different web objects

Occasional Contributor

Comparing 2 numbers contained in different web objects



I'm struggling trying to compare 2 numbers , each of them contained in different web objects:


number_rooms_withou_filters.pngfirst web object


number_rooms_after_applying_filters.pngsecond web object


I want to check if the first number (1270) is greather than the second one (514),after applying filters.

How can I do that by keyword test and also with scripting test?


For example if I use the property contentText to compare this 2 objects, TestComplete take the whole "Madrid: 514 encontrados" and I only want to compare the numbers inside the text (1270 v/s 514)


See pictures attached to get context, object spy, and Name Mapping

Community Hero

You will need to use aqString methods to pick out the numbers you need.  They are actually still strings at that point, so then you'll need to use aqConvert to make them numbers and then you can compare them. There are keyword test and scripting examples in both of these.

[Community Hero]
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
Community Hero

Convert both values in numbers with regEx.

See here (look for Getting numerical values from string)



function ExtractNumber(Str, DefaultValue)
  var MatchArr, re;
  re = /[-+]?\d*\.?\d+([eE][-+]?\d+)?/gm; //Specify the regular expression
  MatchArr=Str.match(re); //Search for occurrences
  //If no numbers were found then return default value
  if (MatchArr==null) return DefaultValue
    //Else, convert a string with first occurrence into a number
    else return aqConvert.StrToFloat(MatchArr[0]);



 So you'll have something like that :


let value1 = ExtractNumber(WebObject1.Property, -1);
let value2 = ExtractNumber(WebObject2.Property, -1);
let value1IsGreaterThanValue2 = value1 > value2;



Un sourire et ça repart

Showing results for 
Search instead for 
Did you mean: