[英]Select Date from DatePicker using Selenium Webriver
這是我的代碼:
for(int i=1;i<=5;i++)
{
driver.findElement(By.id("fromdate")).click();
List<WebElement> allDates=driver.findElements(By.xpath("//table[@class='ui-datepicker-calendar']//td"));
String ee = String.valueOf(i);
for(WebElement ele:allDates)
{
String date=ele.getText();
if(date.equalsIgnoreCase(ee))
{
ele.click();
Thread.sleep(500);
}
System.out.println(i);
Thread.sleep(500);
}
}
我想選擇從“ 1”到“ 5”的日期(按循環),這樣我就可以應用該循環從日期“ 1”到“當前日期”進行選擇。
請檢查以下代碼是否工作正常:
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
Date date = new Date();
String a = (dateFormat.format(date));
LocalDate localDate = LocalDate.now();
int dates = localDate.getDayOfMonth();
String t[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" ,"16", "17", "18", "19", "20", "21", "22", "23"," 24", "25", for (int i = 0; i <= dates - 3; i++) {
driver.findElement(By.id("drawdate")).click();
WebElement dateWidget = driver.findElement(By.id("ui-datepicker-div"));
List<WebElement> allDates = driver.findElements(By.xpath("//table[@class='ui-datepicker-calendar']//td"));
for (WebElement ele : allDates) {
String datee = ele.getText();
if (datee.equalsIgnoreCase(t[i]) && !datee.equalsIgnoreCase(a)) {
ele.click();
Thread.sleep(500);
break;
}
}
我已經解決了我的問題,現在我可以選擇日歷中的所有日期,也可以選擇當月的第一天到今天的所有日期。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.