I am trying to create a method to click particular date, based on the month and year (I want to pass only date, month and year in the method as parameter).
Also I searched over internet but I didn't get the solution for my query.
Below are the my approach and my testing sample application url.
My Approach:
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 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;
}
解决方案
This code might be of some help.
try{
WebElement dateWidget = driver.findElement(By.xpath(OR.getProperty(object)));
List rows = dateWidget.findElements(By.tagName("tr"));
List columns = dateWidget.findElements(By.tagName("td"));
for (WebElement cell: columns){
if (cell.getText().equals(data))
{
cell.findElement(By.linkText(data)).click();
break;
}
}
}catch(Exception e){
return Constants.KEYWORD_FAIL+" -- Not able to select the date"+e.getMessage();
}