Using regular expressions in ReplaceAll function


I am trying to use replaceAll function to replace a text string in my application.
I retrieve ‘Quantity on hand’ from my app which is a string into a variable QtyOnHand
QtyOnHand = ‘200.00’
Then I want to replace it with a string ‘10000’
Using replaceAll function, as below
QtyToReplace = QtyOnHand.replaceAll(‘*.00’,‘10000’)
println('QuantitytoReplace = ’ + QtyToReplace)
Get errors. What is the correct regular expression to use in this case?

Appreciate any help I can get.


Wanted to do it with a settext function. Not allowing me to enter a number 10000.
WebUI.setText(findTestObject(‘Poonam/input_QuantityonHand’), ‘800.00’)

The heading is “Quantity on hand” and I would think it would want only an integer value–without decimal point–as you would only want complete/whole products, no partials. Should you be allowed to enter a decimal number?

Anyways, how about:

WebUI.setText(findTestObject('Poonam/input_QuantityonHand'), '800.00')

Thanks for your reply. I tried cleartext. It clears the text but then does not set the text correctly and appends to the 0.00. Looks like a problem in the application. When I run a recorded script, it used settext to enter the value with a decimal point, and there were no issues. I use the same statement and it gives me erros. Screenshots below of cleartext being used and then settext to set the value

In the code
if (QtyOnHand_Actual <= 500) {
//If QtyOnHand < 500 make it 10000
WebUI.setText(findTestObject(‘Poonam/input_QuantityonHand’), ‘10000’)
//WebUI.sendKeys(findTestObject(‘Object Repository/Poonam/input_Quantity on Hand_quantity_on_hand’), ‘800.00’)
QtyOnHandAfterInvAdded = WebUI.getAttribute( (findTestObject(‘Poonam/input_QuantityonHand’)), “value” )
println('Quantity On Hand After Inventory added= ’ + QtyOnHandAfterInvAdded)‘Poonam/input_btnSAVE’) )

Script below which Katalon recorded with decimal value and using settext. Running this script has no issues in setting the value to 800.00

WebUI.setText(findTestObject(‘Object Repository/PoonamTwo/input_Quantity on Hand_quantity_on_hand’), ‘800.00’)‘Object Repository/PoonamTwo/input_Defines the Available quantity to dis_09d21d’))

Hi @pasthana, try the following:

WebUI.enhancedClick(findTestObject(‘Poonam/input_Quantity on Hand_quantity_on_hand’))
WebUI.clearText(findTestObject(‘Poonam/input_Quantity on Hand_quantity_on_hand’))
WebUI.sendKeys(findTestObject(‘Poonam/input_Quantity on Hand_quantity_on_hand’), ‘800.00’)


Please use “Code Formatting” markdown syntax to preset your codes better readable.

There is a common confusion running through this thread: the mixing up of string values and numeric values.

Most WebUI APIs (e.g.setText) deal with string values.

@pasthana please make sure YOU are clear about what is a string and what is a numeric value. For example:

No, it didn’t. It recorded a string, "800.00" which is not a decimal value.

You did not set the value 800.00, you set the value '800.00' – again, a string.

Going back to your OP, I see no reason why you need to use a regular expression.

Can you please post back with a clear statement as to what you want to achieve and the current status of your test case. Thanks.

Thanks a ton Dave. The enhancedClick, clearText and sendKeys methods worked like a charm. My string got set to ‘800.00’ as I had wanted.

Hi Russ

My statement was a bit unclear when I said Katalon recorded with decimal value and settext. I had meant to say Katalon recorded the string ‘800.00’ using setText method. I had wanted a string there. Whereas in my code when I had wanted to compare that string value to a numeric I had converted that string to a numeric and compared it to a number I wanted. Using Dave’s solution posted here using enhancedClick, clearText and sendKeys to send the string ‘800.00’ worked. Appreciate your reply! Thanks

1 Like