我正在尝试创建一个方法来根据月份和年份单击特定的日期(我只想在方法中传递日期、月份和年份作为参数)。
我还通过互联网搜索,但没有得到我的查询的解决方案。
下面是我的方法和我的测试示例应用程序 URL。
我使用的网址: http://www.cleartrip.com/
我的方法:
public static WebElement selectDatefromMultiDate(WebDriver driver, String date, String year,String month) throws IOException, InterruptedException {
driver.findElement(By.id("DepartDate")).click();
WebElement dates = driver.findElement(By.className("ui-state-default"));
List<WebElement> day=dates.findElements(By.tagName("a"));
String calMonth = driver.findElement(By.className("ui-datepicker-month")).getText();
System.out.println(calMonth);
String calYear = driver.findElement(By.className("ui-datepicker-year")).getText();
System.out.println(calYear);
for (WebElement cell: day){
if(calYear.equalsIgnoreCase(year)){
if (calMonth.equalsIgnoreCase(month)){
if (cell.getText().equals(date)){
cell.findElement(By.linkText(date)).click();
}
}
break;
}
}
return element;
}
最佳答案
您实际上不需要直接操作日期选择器。您可以直接在输入
字段中输入日期字符串。它只需采用正确的格式,例如:
WebElement dateInput = driver.findElement(By.id("DepartDate"));
dateInput.sendKeys("Sat, 6 Jun, 2015");
现在,您需要 create a date from year, month, day传入的参数和 format the date into the desired date string format使用SimpleDateFormat
.
关于java - 日期选择器 - selenium webdriver java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30468289/