How to convert String to int in Katalon


I am running following code and getting compilation error for the lines where I am parsing String to Int.
List ShiftGrid_Rows= DriverFactory.webDriver.findElements(By.xpath(’//tbody/tr’))
for (WebElement ShiftGridRow:ShiftGrid_Rows)
String Guest_to_Shift_Ratio= ShiftGridRow.findElement(By.xpath(’/td[2]’)).getText();
Int Guest_Ratio= Integer.parseInt(Guest_to_Shift_Ratio)
println ('Guest to shift Ratio is: '+Guest_to_Shift_Ratio)

		String Guest_Count= WebUI.getText(findTestObject('Object Repository/Locators/Events/Shift Grid Panel/Guest_Count_Total'))
		Int Guest_Count_Int= Integer.parseInt(Guest_Count)
		println ('Guest Count is: '+Guest_Count)
		Int Expected_Projected_Shifts= Guest_Ratio/Guest_Count_Int
		Mod= Guest_to_Shift_Ratio%Guest_Count
		if (Mod!=0) {
			Expected_Projected_Shifts= Expected_Projected_Shifts+1
		else {
			Expected_Projected_Shifts= Expected_Projected_Shifts
		String Actual_Projected_Shifts = ShiftGridRow.findElement(By.xpath('/td[3]')).getText()
		Int Projected_Shifts= Integer.parseInt(Actual_Projected_Shifts)
		//WebUI.verifyEqual(Actual_Projected_Shifts, Expected_Projected_Shifts)
		Assert.assertEquals(Projected_Shifts, Expected_Projected_Shifts);

Because I have to some math operations, I need to convert Guest_to_Shift_Ratio and Guest_Count in Integers. But I get the following Compilation error.

11-26-2017 08:32:57 PM - [ERROR] - Test Cases/Events/Create Event- Valid Inputs FAILED because (of) org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

file:/C:/Users/b.rani/git/schedule-xpress-katalon/Scripts/Common/Test%20cases%20to%20be%20reused/Shift%20Grid%20Panel/Script1506712948187.groovy: 65: unable to resolve class Int
@ line 65, column 8.
Int Guest_Ratio= Integer.parseInt(Guest_to_Shift_Ratio)

file:/C:/Users/b.rani/git/schedule-xpress-katalon/Scripts/Common/Test%20cases%20to%20be%20reused/Shift%20Grid%20Panel/Script1506712948187.groovy: 69: unable to resolve class Int
@ line 69, column 8.
Int Guest_Count_Int= Integer.parseInt(Guest_Count)

file:/C:/Users/b.rani/git/schedule-xpress-katalon/Scripts/Common/Test%20cases%20to%20be%20reused/Shift%20Grid%20Panel/Script1506712948187.groovy: 72: unable to resolve class Int
@ line 72, column 8.
Int Expected_Projected_Shifts= Guest_Ratio/Guest_Count_Int

file:/C:/Users/b.rani/git/schedule-xpress-katalon/Scripts/Common/Test%20cases%20to%20be%20reused/Shift%20Grid%20Panel/Script1506712948187.groovy: 86: unable to resolve class Int
@ line 86, column 8.
Int Projected_Shifts= Integer.parseInt(Actual_Projected_Shifts)

4 errors

I have solved the problem. Thanks

Hi Rani,

able to advise how you do it?

How you solve the problem, can you please advise

Use the Groovy method: .toInteger();

This is my code which is converting string to integer successfully.

def Guest_Count = WebUI.getAttribute(findTestObject(‘Object Repository/Locators/Events/Shift Grid Panel/Guest_Count_Total’),


    def Guest\_Count\_int = Guest_Count.toInteger()

    WebUI.println('Guest Count is: ' + Guest_Count)

    WebUI.comment('Verify that projected shifts are equal to as expected. Get the total number of rows in shift grid and calculate the projected shifts and verify with actual projected shifts ')

    for (def index = 1; index <= Number\_of\_Rows; index++) {

        def Guest\_to\_Shift_Ratio = DriverFactory.webDriver.findElement(By.xpath(('//table\[@class=\\'k-selectable\\'\]/tbody/tr\[' + 

                index) + '\]/td\[2\]')).getText()

        if (Guest\_to\_Shift_Ratio == 'complex') {

            WebUI.println('Guest to shift ratio is: ' + Guest\_to\_Shift_Ratio)



        def Guest\_Ratio = Guest\_to\_Shift\_Ratio.toInteger()

        WebUI.println('Guest to shift Ratio is: ' + Guest_Ratio)

        Expected\_Projected\_Shifts = Guest\_Count\_int.intdiv(Guest_Ratio)

Its not working for me. Any additional package needs to be added. Please suggest.

Try with importing this package
import java.lang.Integer as Integer

You may see strike line on ‘tointeger()’ method which is totally fine. Or if it still doesn’t work, can you post what error are you getting?

Thanks Bhawna,

It worked for me as well.

Hi Bhawna,

I am getting below error while converting string to int:

scaCostInt = scaCosts.toInteger() FAILED.
java.lang.NumberFormatException: For input string: “2913013.00”

I already added “import java.lang.Integer as Integer” package.

It would be great if you can help me out on this.

Thanks in advance


your input string is not Integer, but number with floating point (Float / Double).

String s = “2913013.00”
Double d = Double.parseDouble(s)

You should work with this data type instead of int.

Thank you very much Marek. It solved my main problem.

But Settext statement is not able to enter this Double value into the desired text box. Neither giving any error nor its entering any value to the corresponding field.
Though I have done some workaround for this, I mean writing that value into my test data sheet(excel), doing needed calculation there and writing back from that excel sheet to the text field. But I think there must be a easy way to entering such types of values.

Thanks and Regards

WebUI.setText method expects string value, so you get an error. You can convert your double value to string using toString() method.

Double finalResult = // your calculation here
WebUI.setText(testObject, finalResult.toString())

Thank you so much Marek for the prompt reply.

But this conversion (double value to string) not working properly for decimal values as the “.” is removed which makes incorrect value entered into the text field. My final value is $323,344,4.43 but after conversion i am getting $323,344,443

Hi Everyone,

My above problem with decimal values is due to the restrictions on the text field in my app, for entering “.” which I came to know later. It was not related to Katalon Studio.

I am really sorry to bother you.



Im new to Katalon.

I have similar issue as above.
My test steps is as:

  1. Get text “Bank Fee”
  2. Convert String to number
  3. Get text “offline Bank Fee”
  4. Convert String to number.
  5. Get sum of New_BankFee = “Bank Fee” + “Offline Bank Fee”

//Get Bank Fee
WebUI.scrollToElement(findTestObject(‘Ob_Bank Transaction Log/Browse/_Listing/td_Total_BankFee’), 2)

String Total_BankFee = WebUI.getText(findTestObject(‘Ob_Bank Transaction Log/Browse/_Listing/td_Total_BankFee’), FailureHandling.STOP_ON_FAILURE)

def x = Double.parseDouble(Total_BankFee)

WebUI.printIn(‘Total Bank Fee is:’ + Total_BankFee)

//‘0 = Offline Bank Fee’
WebUI.waitForElementClickable(findTestObject(‘Ob_Bank Transaction Log/Browse/filter_PaymentType’), 2)

WebUI.selectOptionByValue(findTestObject(‘Ob_Bank Transaction Log/Browse/filter_PaymentType’), ‘0’, true)

WebUI.waitForElementClickable(findTestObject(‘Ob_Bank Transaction Log/Browse/btn_Apply’), 2)‘Ob_Bank Transaction Log/Browse/btn_Apply’), FailureHandling.STOP_ON_FAILURE)


WebUI.waitForElementClickable(findTestObject(‘Ob_Bank Transaction Log/Browse/_Listing/td_TotalAmount’), 2)

//String s = Total_OfflineBankFee
String Total_OfflineBankFee = WebUI.getText(findTestObject(‘Ob_Bank Transaction Log/Browse/_Listing/td_TotalAmount’), FailureHandling.STOP_ON_FAILURE)

def y = Double.parseDouble(Total_OfflineBankFee)

WebUI.printIn(‘Total Offline Bank Fee is:’ + Total_offlineBankFee)

I got this error:
Test Cases/TC_Bank Transaction/TC_Payment Report/TC_TEST2 FAILED.
java.lang.NumberFormatException: For input string: “-636,705.00”
at java_lang_Double$ Source)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(
at com.kms.katalon.core.main.TestCaseExecutor.runScript(
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(
at com.kms.katalon.core.main.TestCaseExecutor.execute(
at com.kms.katalon.core.main.TestCaseMain.runTestCase(
at com.kms.katalon.core.main.TestCaseMain.runTestCase(
at com.kms.katalon.core.main.TestCaseMain$runTestCase$ Source)

Anyone can help me?

I think the presence of the , in the string makes it invalid to be a Double.

Please try the accepted answer here:

1 Like

It works now by removing the comma.
Thank you very much.