Python aqConvert.StrToInt not working: argument is not a number
Hi,
I´m very new to TestComplete and trying a simple Keyword-test with the Windows calculator clicking 5 * 5 = 25. I run the test and converted the test to a Python script. All I´m trying to do is to convert the result from the output (in this case 25) from a string to an integer using aqConvert.StrToInt. I already checked the variable type with aqObject.GetVarType. The variable is definetly a string. Trying aqConvert.VarToInt. also raises an error. Here´s the code snippet I use and i also added a screenshot of the error. Can anyone please help me, what´s going wrong here? I can´t see any mistakes in my script.
def Test1():
# calculate 5 * 5 with Windows-Calculator (result = 25)
#Clicks the 'F_nf' object. (the Five-Button.Click)
Aliases.Microsoft_WindowsCalculator.Rechner.LandmarkTarget.Zehnertastatur.F_nf.Click()
#Clicks the 'Multiplizieren_mit' object.(the Multiply.Click)
Aliases.Microsoft_WindowsCalculator.Rechner.LandmarkTarget.Standardoperatoren.Multiplizieren_mit.Click()
#Clicks the 'F_nf' object. (the Five-Button.Click)
Aliases.Microsoft_WindowsCalculator.Rechner.LandmarkTarget.Zehnertastatur.F_nf.Click()
#Clicks the 'Gleich' object. (the Equals-Button.Click)
Aliases.Microsoft_WindowsCalculator.Rechner.LandmarkTarget.Standardoperatoren.Gleich.Click() # (Equal-Button.Click)
#Clicks the 'normalOutput' object.
Aliases.Microsoft_WindowsCalculator.Rechner.LandmarkTarget.Die_Anzeige_lautet_0_.textContainer.normalOutput.Click(38, 37) # (the result output)
# check if 'normalOutput' exists
if Aliases.Microsoft_WindowsCalculator.Rechner.LandmarkTarget.Die_Anzeige_lautet_0_.textContainer.normalOutput.Exists:
Log.Message("everything is fine") # it works 🙂
else:
Log.Error("nothing is fine")
res = Aliases.Microsoft_WindowsCalculator.Rechner.LandmarkTarget.Die_Anzeige_lautet_0_.textContainer.normalOutput
value = res.Text
# check the type of variable 'value'
TypeID = aqObject.GetVarType(value)
if TypeID == varOleStr:
str = "String" # variable 'value' is a String
Log.Message("TypeID: " + aqConvert.VarToStr(TypeID) + ", Type: " + str + ", Value: " + aqConvert.VarToStr(value))
# Converting the String to an Integer using aqConvert.StrToInt()
test = aqConvert.StrToInt(value) ########### -> Here´s the Problem: Python runtime error: The argument is not a number.
# check the result
if test == 25:
Log.Message("Result is 25")
else:
Log.Message("Result is NOT 25")
Hi,
> they are unicode characters, not showing up in the log-message.
This is what I meant when thought "to check html markup on the page for the '25' value".
The quick idea is to use regular expression. For example (untested regexp):
if (aqObject.CompareProperty(value, BuiltIn.cmpMatches, '^[^0-9]*25[^0-9]*$', false, BuiltIn.lmNone))
Log.Checkpoint('Value equals to 25');
...
https://support.smartbear.com/testcomplete/docs/reference/misc/regular-expressions.html