I need to scroll recyclerview, which contains student name and student performance and need to scroll till end to print the all the student details in recyclerview

I need to scroll till end and print all the items in recycler

  1. Grab all the visible names and performances on the screen and save them locally.
  2. Scroll from the last element to the first element to reveal a fresh set of names & performances.
  3. Grab all the names and performances again, but save only the ones that don’t exist in your local collection of saved names.
  4. Repeat steps 2 and 3 until no new names have been added in step 3.

Thanks for the quick reply, The child items are dynamic items, if possible can you please help me with the code?

below is my code which print the visible student name and student performance but it is not scrolling till the end.

	WebElement recyclerView = driver.findElement(By.id("com.hurrey.ai:id/recyclerView"));

	List<WebElement> childElements = recyclerView.findElements(By.className("android.widget.LinearLayout"));

	List<String> studentNames = new ArrayList<>();
	List<String> studentPerformances = new ArrayList<>();

	for (WebElement childElement : childElements) {
	    WebElement nameElement = childElement.findElement(By.className("android.widget.TextView"));
	    String studentName = nameElement.getText();

	    WebElement performanceElement = childElement.findElements(By.className("android.widget.TextView")).get(1);
	    String studentPerformance = performanceElement.getText();


	for (int i = 0; i < studentNames.size(); i++) {
	    System.out.println(    "Student Name:"+studentNames.get(i)+""
	    		+ " and Student Performance: " + studentPerformances.get(i));

It’s no easy task coding this the right way, there’s a few exceptions to be mindful of.
In pseudocode I’d do something like this:

var namesAndGradesList = new List();
bool newEntriesWereFound = true;
  // A valid row is that which has a name and a percentage VISIBLE
  var rows = driver.FindElements(By.Id("relativeLayout"));
  var validRows = rows.Select(item => item.FindElements(By.Id("studentName")).Count != 0 && 
  item.FindElements(By.Id("studentGrade")).Count != 0);

  for (int i =0; i < validRows.Count; i++)
      var name = validRows[i].FindElement(By.Id("studentName")).Text;
      var grade = validRows[i].FindElement(By.Id("studentGrade")).Text;
      var nameAndGradeString = $"{name} has grade {grade}";
      if (namesAndGradesList.Contains(nameAndGradeString))
      // then it's possible that we've scrolled all the way down and no new names were found
      newEntriesWereFound = false;
        newEntriesWereFound = true;
    catch (NoSuchElementException)
       // It could be that after scrolling, a row does not display both the name AND the grade on the screen, making it impossible to grab both. It's not a problem because after a scroll they WILL be visible.
  if (newEntriesWereFound == false)
    // If after going through an entire screen of names, no new ones were found, we've gone through them all and it's safe to quit the while loop
  // Scroll from the last to the first to reveal a fresh set of rows
  ScrollMethod(startingFrom: validRows.Last(), goingTo: validRows.First());

foreach(item in namesAndGradesList)
// **name** has grade **x**

What’s bad about this implementation:

  1. I have to go through the rows multiple times:
    Once to fetch them
    Another time to determine which are valid by looking at what children they have
    Another time to fetch the text from said children
  2. If there’s 2 students with the exact same name & grades, the final list will only display an entry for the FIRST one.
  3. There should be a stopwatch included so this loop does not go ad infinitum if something goes wrong.

it should be one more check:

  • when name OR grade = null (element NOT found e.g. partially visible) we skip add this item. will add after next scroll

@Dragos_Losonti I’m using Java with appium, The code you provided was C++ (if I’m not wrong), the above code was provided by me fetching the visible details after fetching I need to scroll the recyclerview

I wrote it in a C# fashion almost but didn’t bother with 100% correct grammar. It’s not that far from Java either; should be easy to convert. Probably chatGPT can do it for you; it could even implement the scroll method if you ask it properly.

Also, what Aleksei mentioned is covered by the try-catch block I’m pretty sure. Good luck.

aaa yes…