Is It possible to grab the numeric value from a field?

Is it possible to grab the numeric value from the field in katalon and use the value to compare with data in a database? i tried looking all over for a discussion for this but couldn’t find anything?

You can use, WebUI.GetText and save in Variable.

smp_useremail = WebUI.getText(findTestObject('Shipping_Method_Page/User_Email_Address'))

Then compare the variable with value in DB

I just tried this and the i ran a print statement to see if it capture the number but nothing printed

Can you please share the element HTML and code ?

I just the used the Get Attribute instead

1 Like

Good for you. WebUI.getText does not return the content of an HTML element’s value attribute – it returns the “inner text” within an element (where element == tag-pair).

1 Like

I mis read your post thinking you want to grab value = text on a webpage

1 Like

is it possible to grab the values i get and subtract them

Sure

def valueA = WebUI.getAttribute(TestObjectA, 'value')
def valueB = WebUI.getAttribute(TestObjectB, 'value')
def result = valueA - valueB
println result
1 Like

Thank you so much

Hey so its not actually subtracting both values. it just prints valueA and doesn’t subtract the values.

Can i cast these values into a integer?

I don’t know what that means. The subtract operation subtracts one value from another value. So what do you mean by “subtracting BOTH values”?

basically its not subtracting the two values. it just stores the first value.

ValueA = 64
ValueB = 54

Result = ValueA - ValueB

printed results would be 64. So its only taking valueA and not subtracting from valueB

Well, that’s surprising - def should work. What does this do?

int valueA = 64
int valueB = 54
int result = valueA - valueB

i get the correct answer. is there a way i can cast them into integers?

Hi
You can use int intA = valueA as Integer

1 Like

Right. Good.

So now you might need to cast your element values before using the math:

int valueA = WebUI.getAttribute(TestObjectA, 'value').toInteger()
1 Like

(Stack trace: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object ‘64’ with class ‘java.lang.String’ to class ‘int’

i received this error

Check my previous - edited.

1 Like

Thank you it worked!