There is an problem with the Recursion in Java. Method is returning empty list

0 votes

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;

}

Jun 6, 2018 in Selenium by Martin
• 4,220 points
65 views

1 answer to this question.

0 votes
checkMonth(driver)

Ignore the List returned by that call.

Perhaps you want to add the output of that call to the overall output returned by your method (the daysList list):

daysList.addAll(checkMonth(driver));

answered Jun 6, 2018 by jonss

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

What is the problem with the Alert function in the Selenium IDE

To simulate the button OK and click ...READ MORE

answered Mar 5 in Selenium by Surya
• 970 points
259 views
0 votes
1 answer

Is there any method to reset the HTML text box in Selenium Webdriver?

Hey Anushka, you can use clear() function to ...READ MORE

answered Jun 24 in Selenium by Abha
• 27,180 points
53 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,110 points
965 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
1,125 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
868 views
0 votes
1 answer

Is there a way to pass on the options/ flags to Selenium if i'm scripting in Python?

This is the usage: from selenium import webdriver from ...READ MORE

answered Jun 8, 2018 in Selenium by king_kenny
• 3,650 points
301 views
0 votes
1 answer

How to scroll until the element is in view using Selenium2Library Keyword?

You have to download the ExtendedSelenium2Library from ...READ MORE

answered Jun 25, 2018 in Selenium by Samarpit
• 5,130 points
2,562 views