从当前到下一个即将到来的日期的日历显示日期。我需要在每次运行脚本时选择当前日期。
日历如下所示: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;
}
}
答案 0 :(得分:0)
试试这个 -
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yy");
Date today = Calendar.getInstance().getTime();
String date = dateFormat.format(today);