Reputation: 148
I'm working in MakeMyTrip site for handling the calender. After selecting the from date i want to select to date after 7 or 8 days from the selected from date..
Link: https://www.makemytrip.com/
I'm able to select the current date, using the class name which has today
I don't know how to handle selecting the to date like after n number of days after from date
@FindBy(how = How.XPATH,using = "//div[@class = 'DayPicker-Month'][1]//div[@class='DayPicker-Body']//div[contains(@class,'DayPicker-Day')]")
List<WebElement> DepartureDateList;
//Selecting Departure Date
public void selectDepartureDate() {
for ( WebElement date : DepartureDateList) {
if (date.getAttribute("class").contains("--today")) {
date.click();
break;
}
Upvotes: 0
Views: 1293
Reputation: 14135
Here is the simple solution.
First get the nth day using the below code.
int numberOfDays = 7;
DateFormat dateFormat = new SimpleDateFormat("MMM dd yyyy");
Calendar cal = Calendar.getInstance();
cal.add(Calendar.DATE, numberOfDays);
String toDate = dateFormat.format(cal.getTime());
System.out.println(toDate);
Then select the data in the calendar using the below xpath.
String toDateXpath = "//div[@class='DayPicker-Day' and contains(@aria-label,'" + toDate + "')]"
driver.findElement(By.xpath(toDateXpath)).click();
Upvotes: 1