Date Picker

Kindly help me in the below scenario:
I have a date picker option in my application. I am trying to capture the date for both Lease start date and Lease Finish Date which is a Read-Only field.

Hence I tried using Javascript function for both the fields. Using this functionality the value is getting entered in both the read-only fields. But the problem is when I click on Submit at last both the date values are getting cleared (which is a mandatory field) and throws error. Kindly help me on this…

****Start Date****

WebElement leasestartdate = WebUiCommonHelper.findWebElement(findTestObject(‘Object Repository/New Request objects/Page_Online Lease Request/input_ctl00cphBodyucCalendarSt’),

10)

WebUI.executeJavaScript(‘arguments[0].value=\‘26-Jul-2018\’’, Arrays.asList(leasestartdate))

****End Date****

WebElement leasefinishdate = WebUiCommonHelper.findWebElement(findTestObject(‘Object Repository/New Request objects/Page_Online Lease Request/input_ctl00cphBodyucCalendarEn’),

10)

WebUI.executeJavaScript(‘arguments[0].value=\‘27-Jul-2018\’’, Arrays.asList(leasefinishdate))

Help.jpg

I’m just taking a wild guess here…

Because you are not using the date-picker to choose a date, it’s possible that some other code that is required to be executed is being skipped/missed.

Also, it’s entirely possible that the input control you are referencing is not the eventual control that will be transmitted when you click submit.

Also, and again because you have skipped the date-picker, perhaps an onchange event has been missed.

Check in the developer tools to see if there is an event handler attached to the input control(s). Also, post a snippet of the relevant HTML.

Can you get the text box id? I used this below to manually force a date in a very similar situation where I didn’t want to bother with the calendar date picker.

WebUI.executeJavaScript("document.getElementById('textboxid').value = '01/10/2018'", null)

It looks like you are using the Katalon documentation example, which just did not work for me.

Thanks all for the response ! I have found a way to pass the date. Hope this will be useful.

@Keyword

def setAttributeUsingJS(String Jscript) {

WebDriver driver = DriverFactory.getWebDriver()

JavascriptExecutor executor = ((driver) as JavascriptExecutor)

executor.executeScript(Jscript)

}

//--------Code snippet for leasestartdate------------------

WebUI.focus(findTestObject(‘New Request objects/Page_Online Lease Request/input_ctl00cphBodyucCalendarSt’))

setAttributeUsingJS(‘document.getElementById(“ctl00_cphBody_ucCalendarStartDate_txtDateCtrl”).removeAttribute(“readonly”),null’)

WebUI.setText(findTestObject(‘New Request objects/Page_Online Lease Request/input_ctl00cphBodyucCalendarSt’), ‘27-Jul-2018’)

//--------Code snippet for leasefinishdate------------------

WebUI.focus(findTestObject(‘Object Repository/New Request objects/Page_Online Lease Request/input_ctl00cphBodyucCalendarEn’))

setAttributeUsingJS(‘document.getElementById(“ctl00_cphBody_ucCalendarEndDate_txtDateCtrl”).removeAttribute(“readonly”),null’)

WebUI.setText(findTestObject(‘Object Repository/New Request objects/Page_Online Lease Request/input_ctl00cphBodyucCalendarEn’), ‘28-Jul-2018’)

Kindly add the necessary import statements:

import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory

import org.openqa.selenium.JavascriptExecutor as JavascriptExecutor

import com.kms.katalon.core.webui.common.WebUiCommonHelper as WebUiCommonHelper

import com.kms.katalon.core.annotation.Keyword as Keyword

import org.openqa.selenium.WebDriver as WebDriver

import org.openqa.selenium.WebDriver.Timeouts as Timeouts

2 Likes

Devanadan said:

Thanks all for the response ! I have found a way to pass the date. Hope this will be useful.

@Keyword

def setAttributeUsingJS(String Jscript) {

WebDriver driver = DriverFactory.getWebDriver()

JavascriptExecutor executor = ((driver) as JavascriptExecutor)

executor.executeScript(Jscript)

}

//--------Code snippet for leasestartdate------------------

WebUI.focus(findTestObject(‘New Request objects/Page_Online Lease Request/input_ctl00cphBodyucCalendarSt’))

setAttributeUsingJS(‘document.getElementById(“ctl00_cphBody_ucCalendarStartDate_txtDateCtrl”).removeAttribute(“readonly”),null’)

WebUI.setText(findTestObject(‘New Request objects/Page_Online Lease Request/input_ctl00cphBodyucCalendarSt’), ‘27-Jul-2018’)

//--------Code snippet for leasefinishdate------------------

WebUI.focus(findTestObject(‘Object Repository/New Request objects/Page_Online Lease Request/input_ctl00cphBodyucCalendarEn’))

setAttributeUsingJS(‘document.getElementById(“ctl00_cphBody_ucCalendarEndDate_txtDateCtrl”).removeAttribute(“readonly”),null’)

WebUI.setText(findTestObject(‘Object Repository/New Request objects/Page_Online Lease Request/input_ctl00cphBodyucCalendarEn’), ‘28-Jul-2018’)

Kindly add the necessary import statements:

import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory

import org.openqa.selenium.JavascriptExecutor as JavascriptExecutor

import com.kms.katalon.core.webui.common.WebUiCommonHelper as WebUiCommonHelper

import com.kms.katalon.core.annotation.Keyword as Keyword

import org.openqa.selenium.WebDriver as WebDriver

import org.openqa.selenium.WebDriver.Timeouts as Timeouts

Good Job and thanks for sharing your solution