I am trying to return an array list from my method which use recursion to populate that list. But the method always returns an empty list. I've checked in debug mode the list is getting populated in second go but still method return 0 element.
Below is code for my method.
private static List<WebElement> checkMonth(WebDriver driver) {
List<WebElement> months = driver.findElements(By
.xpath("//div[@class='DayPicker-Caption']"));
List<WebElement> daysList = new ArrayList<WebElement>();
for (WebElement monthEl : months) {
if (monthEl.getText().contains(month)) {
daysList.addAll(driver.findElements(By
.xpath("//div[contains(text(),'" + month
+ "')]/..//div[@aria-disabled='false']/div")));
}
}
if (daysList.size() == 0) {
driver.findElement(
By.xpath("//span[@class='DayPicker-NavButton DayPicker-NavButton--next']"))
.click();
checkMonth(driver);
}
return daysList;
}