【发布时间】:2017-05-18 12:58:46
【问题描述】:
从当前日期到下一个即将到来的日期的日历显示日期。每次运行脚本时,我都需要选择当前日期。
日历如下所示: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;
}
}
【问题讨论】:
-
您提供了一个截屏视频。截屏视频不会公开其下的 HTML 代码。如果您在为 Selenium 拆分 HTML 方面需要帮助,您需要提供相关的 HTML sn-ps 或 UI 链接(如果它是公开且安全的)。
-
这种方法似乎相当不错。我能知道你收到什么错误信息吗?还要在 for 循环中打印 cell.getText() 值以进行调试