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,320 points
1,066 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

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

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

answered Mar 5, 2019 in Selenium by Surya
• 970 points
2,712 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 25, 2019 in Selenium by Abha
• 28,140 points
1,790 views
0 votes
2 answers

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,500 points
13,649 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,131 views
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,910 points
7,209 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,865 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,710 points
4,980 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,910 points
9,077 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP