0

I am unable to Verify Previous Month arrow should not be present in DatePicker but as it is not present in DOM getting Exception unable to find Such Exception.

void fillDepartureDate() {
    // Date Text
    // driver.findElement(By.xpath("//input[@id='departureCalendar']"));
    wait = new WebDriverWait(driver, 10);
    wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.xpath("//div[@role='application']")));

    // Validate prev Arrow in current month
    //Assert.assertFalse(driver.findElement(By.xpath("//div[@class='DayPicker-NavBar']/span[contains(@class,'prev')]")).isDisplayed());

    // Validate Current month and Year September 2020
    Date dateObj = getCurrentDateObj();
    DateFormat month = new SimpleDateFormat("MMMM" + " " + "y"); // September 2020
    String actualCurrentMonthYear = driver.findElement(By.xpath("//div[@class='DayPicker-Caption']")).getText();
    Assert.assertEquals(actualCurrentMonthYear, month.format(dateObj));

    //weekdays Validation
    calendarWeekdaysValidation();

    // Creating customize Id for selecting current date
    DateFormat date = new SimpleDateFormat("YMMdd");
    String selectDate = "fare_" + date.format(dateObj);

    // Fill Current date 
    DateFormat expectedPopulatedDateValue = new SimpleDateFormat("d MMM");
    driver.findElement(By.xpath("//div[@id=\'" + selectDate + "\']")).click();
    //Verifying selected date should be populated in field
    String populatedDateValue = driver.findElement(By.xpath("//input[@id='departureCalendar']")).getAttribute("value");
    Assert.assertTrue(populatedDateValue.contains(expectedPopulatedDateValue.format(dateObj)));
}

Link : https://www.goibibo.com/flights/

1
  • Can you put the error message? is it unable to find Such Exception?. or unable to find Such Element.?
    – Sachintha
    Sep 14 '20 at 12:32
1

I think you should click day picker next month arrow 1st, then only your element (Previous Month arrow ) will come and appear in the DOM

After that you can verify that element present or not

now your are checking not display and not present element in current DOM that's why it is throwing unable to find Such element

2
  • yep that's correct element is not present DOM and it is throwing Unable to find such element. So, Is there any way where we can validate Prev month arrow should not be present in Current Month calendar ?
    – Palak Soni
    Sep 14 '20 at 17:10
  • ill put separate answer for this one, check that
    – Sachintha
    Sep 15 '20 at 9:24
0

Below code snippet is to check the element is exist or not .Please tryout the code ....

public boolean isElementExist(WebElement element)

    {
        try 
        {
        return element.isDisplayed();
        }
        catch(NoSuchElementException e)
        {
            return false;
        }
    }
0

You can get the count of child elements under then you can implement if else condition like below

  • if that child elements count equal to 2 which means your DOM has Previous and Next Arrows
  • if that child elements count equal to 1 which means your DOM has only one Arrows( this scenario again verify that element is next arrow button or not)

You can get count of the child elements referring following resource HTML DOM childElementCount Property.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.