I have to set text the Current date in an application. So I have Created a Keyword as follows

package date_Picker_Functions

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static java.util.Calendar.*

import java.text.SimpleDateFormat as SimpleDateFormat

import com.kms.katalon.core.annotation.Keyword as Keyword
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

public class Current_Date {

@Keyword

def call(){
	def date = new Date()
	
	def sdf = new SimpleDateFormat("dd/MM/yyyy")
	
	println sdf.format(date)
			
	return sdf.format(date)
	
}

}

Now I have to set text the variable date in the Application. How Can I do this? Can Anyone Please help me to sort it out?

I am getting the Error as,

No signature of method: static com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.setText() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject, com.kms.katalon.core.testobject.TestObject) values: [TestObject - ‘Object Repository/03. Account Payable (AP)/Page_AP Invoice - UPM IBU PEJABAT/Post Date’, …] Possible solutions: setText(com.kms.katalon.core.testobject.TestObject, java.lang.String), getText(com.kms.katalon.core.testobject.TestObject), getText(com.kms.katalon.core.testobject.TestObject, com.kms.katalon.core.model.FailureHandling), setText(com.kms.katalon.core.testobject.TestObject, java.lang.String, com.kms.katalon.core.model.FailureHandling), clearText(com.kms.katalon.core.testobject.TestObject), clearText(com.kms.katalon.core.testobject.TestObject, com.kms.katalon.core.model.FailureHandling)

Hi , I think the error is cause you are trying to set a ‘date’ with the settext method. but settext method im not sure if allows that. I know it allows string format.

Try this:

@Keyword
def getCurrentDate(){
Date date = new Date()
String datePart = date.format(“dd/MM/yyyy”)
return datePart
}

1 Like