I write an automation testing software and have one problem now. In my actual native app I have a ListView like this here:
- ListView
- LinearLayout
- LinearLayout
- LinearLayout
- TextView
- LinearLayout
- LinearLayout
- LinearLayout
- LinearLayout
- LinearLayout
- LinearLayout
- ...
- LinearLayout
... and more.
What I need and want is to get all one level lower LinearLayout (iterative ones, visible and non visible elements) from ListView:
ListView : {LinearLayout, LinearLayout, ...}
With that code I get all childs from ListView, but its to much for me:
listViewChildElements = "[...]android.widget.ListView[1]//android.widget.LinearLayout";
app.getDriver().findElements(By.xpath(listViewChildElements));
In another post I see something with 'count', but I don't understand it.
Thanks for your help and nice to meet you.
With the help of @har07 I write one function, not best or finest solution and not finally, but the 1st step in the right lane:
public static List<String> getAllViewElements(App app){
int i = 0;
List<String> writtenElementsByText = new ArrayList<String>();
while(true){
if(!writtenElementsByText.isEmpty()){
String recentLastItem = writtenElementsByText.get(writtenElementsByText.size()-1);
if(recentLastItem.equals("Alle Themen"))
break;
else
app.getDriver().scrollTo(recentLastItem);
}
List<WebElement> tmp = app.getDriver().findElements(By.xpath(listViewChildElements));
if(writtenElementsByText.isEmpty())
for(WebElement e: tmp){
writtenElementsByText.add(getTextFromElement(e));
}
else
for(WebElement e: tmp){
String activualElemenByText = getTextFromElement(e);
if(!writtenElementsByText.contains(activualElemenByText))
writtenElementsByText.add(activualElemenByText);
}
}
System.out.println(writtenElementsByText.size());
for(String e: writtenElementsByText){
System.out.println("\t-\t"+e);
}
return writtenElementsByText;
}
public static String getTextFromElement(WebElement element){
return element.findElement(By.id(listViewChildElementTextID)).getText();
}