I wanted to iterate through checkboxes and tap on the checkboxes. I wrote foreach loop without using a function and its working but when I had given foreach loop inside a method its showing error as foreach not applicable to type 'io.appium.java_client.android.AndroidElement' .
Code:
For Each loop without using a method - Working
List<AndroidElement> checkbox = (List<AndroidElement>) driver.findElementsById("io.appium.android.apis:id/tasklist_finished");
for (AndroidElement check : checkbox) {
tap(check);
}
For Each loop inside a method - Not Working
List<AndroidElement> checkbox = (List<AndroidElement>) driver.findElementsById("io.appium.android.apis:id/tasklist_finished");
Checkboxes((AndroidElement) checkbox);
public static void Checkboxes(AndroidElement checkbox){
for (AndroidElement check : checkbox) { **-->Issue**
tap(check);
}
Error: java: for-each not applicable to expression type required: array or java.lang.Iterable found: io.appium.java_client.android.AndroidElement
foreach not applicable to type 'io.appium.java_client.android.AndroidElement'