【问题标题】:How can I find the end date of the calendar control in selenium java如何在 selenium java 中找到日历控件的结束日期
【发布时间】:2021-11-17 05:15:59
【问题描述】:

此日历的日期范围为距当前日期 11 天,我如何检查通过脚本输入的日期是否在此范围内,如果脚本中提到的输入日期不在该日期范围内,则选择它否则那么应该点击当前日期。

有一个类可以用来获取当前日期(class="owl-dt-calendar-cell-content owl-dt-calendar-cell-today")calendar

public void selectRequiredOn(String date)
{
    requiredOnClick.click();
    currentDate.getText();
    
    if(currentDate.equals(date))
    {
        currentDate.click();
    }

【问题讨论】:

  • 这个问题你不是昨天还是前几天才问的?是不是删了再问?抱歉,我不了解 Selenium,所以不懂问题,无法回答。

标签: java selenium


【解决方案1】:
public void selectRequiredOn(String date) throws InterruptedException
    {
        requiredOnClick.click();
        Thread.sleep(2000);
        
        WebElement calendarRange = createWebElement("//table[@class='owl-dt-calendar-table owl-dt-calendar-month-table']//td[not(contains(@class,' owl-dt-calendar-cell-disabled ng-star-inserted'))]//span[contains(text(),'"+date+"')]");
        Thread.sleep(2000);
        
        try
        {
        if(calendarRange.isDisplayed())
        {       
            calendarRange.click();
//          WebElement dateClick = createWebElement("//table[@class='owl-dt-calendar-table owl-dt-calendar-month-table']//td[not(contains(@class,' owl-dt-calendar-cell-disabled ng-star-inserted'))]//span[contains(text(),'"+date+"')]");
//          dateClick.click();
            Thread.sleep(2000);
            calendarSetButtonClick.click();     
        }
        else
        {
            currentDate.click();
            Thread.sleep(2000);
            calendarSetButtonClick.click();
        }
        }
        catch(NoSuchElementException e)
        {
            
        }
        
    }

【讨论】:

  • 没有任何解释的代码很少有帮助。 Stack Overflow 是关于学习的,而不是提供 sn-ps 来盲目复制和粘贴。请编辑您的问题并解释它如何回答所提出的具体问题。见How to Answer
猜你喜欢
  • 2020-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-02
  • 1970-01-01
  • 2014-12-05
  • 2022-08-14
  • 2011-12-14
相关资源
最近更新 更多