如何从Telerik(kendo)日期选择器中选择日期

时间:2019-07-09 15:49:04

标签: selenium-webdriver kendo-ui datepicker katalon-studio

在pickDay()方法中选择特定日期时遇到问题。当我指定4时,它将继续选择1。当println date [DAY_OF_MONTH]时,它会打印出4。

我用这个关键字来称呼它:-

  

CustomKeywords.'custom.keywords.RadDatePicker.pickDate'('Object   存储库/ Telerik / RadDateLightWeightPage / img_CalendarPopupButton',   '06 / 04/2019')

class RadDatePicker {

  Date date;
  String obj;

  RadDatePicker() {
  }

  RadDatePicker(String object, String input_date) {
    this.obj = object;
    date = new Date().parse("MM/dd/yyyy", input_date)
   }

  def openCalendar() {...}

  def displayMonth() {...}

  def displayYear() {...}

  def displayDate() {
    return new Date().parse("MMM/yyyy", displayMonth() + "/" + displayYear())
  }

  def pickYear(){...}

  def pickMonth(){...}

  def pickDay() {
    println date[DAY_OF_MONTH]
    WebUI.click(findTestObject('Object Repository/Telerik/RadDateLightWeightPage/a_dayPicker', [('day') : date[DAY_OF_MONTH]]))
  }

  def pickDate() {
    pickYear()
    pickMonth()
    pickDay()
  }

  @Keyword
  def pickDate(String obj, String date) {
    def pick = new RadDatePicker(obj, date)
    pick.openCalendar()
    pick.pickDate()
  }
}

这是日历和HTML

calendar html

1 个答案:

答案 0 :(得分:0)

我通过实现WebDriver并查找包含所要查找的特定xpath的方法找到了解决方法,这是代码

def pickDay() {

  WebDriver driver = DriverFactory.getWebDriver();;
  WebElement datepicker = driver.findElement(By.xpath("//*[@id='ctl00_cphContent_RadDatePicker1_calendar_Top']"));
  datepicker.findElement(By.xpath("//*[(text()=" + date[DAY_OF_MONTH] + ")]")).click();

}