Handling Ranged Calendar with custom keyword

I want to select ranged calendar in my website. Is anyone have idea on how to do it? Because in this type of calendar, the date have same locator. And also, the textbox is non type-able

We need to have a part of the HTML code to see. There will be locators possible but without details of the relevant HTML code or which datepicker is used here… no clue

Well, as for the HTML code, I don’t really have any issue regarding choosing the date itself.

But the problem is when I need to choose date from different month and year for each calendar. Since the next month, next year, previous month, and previous year are the same for both calendar.

I think you are using this one? https://ant.design/components/date-picker/
If you don’t need to test the calendar itself, you could just set the date you want to use directly in the (hidden) input field (defaults to input fields with class “ant-calendar-input”). If you want to test the calendar, you could target the left ‘prev-year-btn’ by something like:

//*[@class=“ant-calendar-range-part ant-calendar-range-left”]//a[@class=“ant-calendar-prev-year-btn”]

and the right one similar:

//*[@class=“ant-calendar-range-part ant-calendar-range-right”]//a[@class=“ant-calendar-prev-year-btn”]

hi,

I have played a bit with this datepicker

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement

import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webui.driver.DriverFactory
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

def x1 = 2
def x2 = 1

Calendar c = Calendar.getInstance();
int monthMaxDays = c.getActualMaximum(Calendar.DAY_OF_MONTH);
println "Current month count of dates: "+monthMaxDays
int day = c.get(Calendar.DATE);
int validDays = monthMaxDays - day
println "Valid calendar days in month: "+validDays

def start = "//*[@placeholder = 'Start date' and @class = 'ant-calendar-range-picker-input']"
def end = "//*[@placeholder = 'End date' and @class = 'ant-calendar-range-picker-input']"

for(int i = 0; i < validDays+1; i++){
	
	WebUI.openBrowser('')
	
	WebUI.navigateToUrl('https://ant.design/components/date-picker/')
	
	WebUI.waitForPageLoad(60)
	
	WebUI.waitForElementPresent(findTestObject('Object Repository/Page_DatePicker - Ant Design/input_Examples_ant-calendar-range-picker-input'),30)

	WebUI.click(findTestObject('Object Repository/Page_DatePicker - Ant Design/input_Examples_ant-calendar-range-picker-input'))
			
	def xpath = "//*/text()[normalize-space(.)='"+x1+"']/parent::*"
			
	def xpath2 = "(.//*[normalize-space(text()) and normalize-space(.)='Sa'])[2]/following::div["+x2+"]"
	
	x1++
	x2++
	
	WebUI.click(makeTO(xpath))
		
	WebUI.click(makeTO(xpath2))
			
	WebUI.delay(2)
	def startDate = WebUI.getAttribute(makeTO(start),'value')
	println startDate
	def endDate = WebUI.getAttribute(makeTO(end),'value')
	println endDate
	
	WebUI.closeBrowser()
}

static TestObject makeTO(String xpath) {
	TestObject to = new TestObject()
	to.addProperty("xpath", ConditionType.EQUALS, xpath)
	return to
  }

@r.klein1 @Timo_Kuisma1

Thanks for the tip