-1

I am having issue in my automation script. I am using selenium tool with java language. My problem is that I want to view the current date after clicking on the calendar and check if in that flight is available or not.

If available then click on that date. If flight is not available in that date then search for next available date that does have a flight and click on that date.

I am not familiar with so much coding. I saw this kind of problem but it is in python. So i did not get.

Ole V.V.
  • 81,772
  • 15
  • 137
  • 161

2 Answers2

1

I have a similar scenario where I compare a date from WebElement with date in data source (XLSX file). Probably best solution provides LocalDate with booleans foo.isBefore(bar) or foo.isAfter(bar) or foo.isEqual(bar) and int foo.compareTo(bar)

pburgr
  • 1,722
  • 1
  • 11
  • 26
0

1) you can get the current data in java but if that date is available or not you have to use isDisplayed from selenium.

`   public static String getCurrentDate() {
        Date date = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String strDate = formatter.format(date);
        System.out.println(strDate);
        return strDate;
    }`
  • 1
    Thanks for wanting to contribute. Please don’t teach the young ones to use the long outdated and notoriously troublesome `SimpleDateFormat` class. At least not as the first option. And not without any reservation. Today we have so much better in [`java.time`, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/) and its `DateTimeFormatter`. – Ole V.V. Mar 06 '19 at 12:14