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?
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?
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.clearText(findTestObject(‘Poonam/input_QuantityonHand’))
WebUI.setText(findTestObject(‘Poonam/input_QuantityonHand’), ‘10000’) //WebUI.sendKeys(findTestObject(‘Object Repository/Poonam/input_Quantity on Hand_quantity_on_hand’), ‘800.00’) //WebUI.delay(5)
QtyOnHandAfterInvAdded = WebUI.getAttribute( (findTestObject(‘Poonam/input_QuantityonHand’)), “value” )
println('Quantity On Hand After Inventory added= ’ + QtyOnHandAfterInvAdded)
WebUI.click(findTestObject(‘Poonam/input_btnSAVE’) )
}
}
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’)
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