如何从 Selenium 的动态日历中选择当前日期?

问题描述 投票:0回答:1

日历显示日期从当前到下一个即将到来的日期。每次运行脚本时我都需要选择当前日期。

日历看起来像这样:https://www.screencast.com/t/EWjncok2Anv

我尝试使用下面的代码,但没有帮助我:

     DateFormat dateFormat2 = new SimpleDateFormat("dd"); 
     Date date2 = new Date();

     String today = dateFormat2.format(date2); 

     //find the calendar
     WebElement dateWidget = driver.findElement(By.id("qs_startdate"));  
     List<WebElement> columns=dateWidget.findElements(By.tagName("div"));  

     //comparing the text of cell with today's date and clicking it.
     for (WebElement cell : columns)
     {
        if (cell.getText().equals(today))
        {
           cell.click();
           break;
        }
     } 
java selenium calendar
1个回答
0
投票

试试这个 -

DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy");
Date today = Calendar.getInstance().getTime();
String date = dateFormat.format(today);
© www.soinside.com 2019 - 2024. All rights reserved.