'Print Count of items whuch is not avaible in screen using selenium java
I have a sceanrio where there is a list of 12 items in a page but at a time, it will display 5 items in the screen,we need to scroll down to get the list of remainig 7 items, I need to print the Number of these items( 0,1,2----11), I have written a for loop in a funtion which will run for the first 5 item till its max size,then again scroll, then again Iam calling the function containing forloop to get number of remaining item. At first ,i can print by giving System.println(i) which will print 0 to 5 but second time when the loop runs, it will again print 0 to 5 for the remaining set of items,intead i need to print 6,7,8 and so on.
Below is the method which iam calling:
switchToggleAndClickInfoIcon(); //first loop will run to print numbers for each list till 7 which is good
scrollToElement("Brakes"); //scroll down for next set of items
switchToggleAndClickInfoIcon(); //again loop will execute but numebr will again print 0 to 7 instead I need 8,9,10,11 etc
Below is the loop implementation:-
public void switchToggleAndClickInfoIcon{
for(int i=0;i<list.size();i++{
System.out.println( "Serial no" +i ,+list.get(i).text());
//here i is printing 0 to 7 when this method is called first which is fine but when again scrolled and called this method again, loop will print 0 to 7, instead i need to print the next 8 , 9,10..... }
Solution 1:[1]
Thanks for the additional info. I have created a sample approach to retrieve the value from the given lastIndex value. it will be holding the last index value to continue the next iteration with as starting index.
public class TestCode {
private static int lastIndex = 0;
public static void main(String[] args) {
List<Integer> value = new ArrayList<Integer>();
for(int i =0;i<10;i++) {
value.add(i);
}
retrieveValueFromList(value);
value.add(10);
value.add(11);
value.add(12);
value.add(13);
value.add(14);
retrieveValueFromList(value);
}
public static void retrieveValueFromList(List<Integer> holder) {
for (int i = lastIndex; i < holder.size(); i++) {
System.out.println("value from the list : "+i);
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vinothkumar Jeeva |
