Reputation: 165
I have this dynamic ListView at my apk Android:
<android.widget.ListView resource-id="br.com.noticias:id/editoria_listview">
<android.widget.LinearLayout>
<android.widget.RelativeLayout>
<android.widget.ImageView content-desc="imagem da noticia em destaque" resource-id="br.com.noticias:id/adapter_editoria_first_news_image">
<android.widget.LinearLayout resource-id="br.com.noticias:id/adapter_editoria_layout">
<android.widget.TextView resource-id="br.com.noticias:id/adapter_editoria_news_editoria_indicator">
<android.widget.TextView resource-id="br.com.noticias:id/adapter_editoria_news_title">
<android.widget.LinearLayout resource-id="br.com.noticiasbr.com.noticias:id/adapter_editoria_layout">
<android.widget.TextView resource-id="br.com.noticias:id/adapter_editoria_news_editoria_indicator">
<android.widget.ImageView content-desc="imagem da noticia" resource-id="br.com.noticias:id/adapter_editoria_news_image">
<android.widget.LinearLayout>
<android.widget.TextView resource-id="br.com.noticias:id/adapter_editoria_news_title">
<android.widget.LinearLayout resource-id="br.com.noticias:id/adapter_editoria_layout">
<android.widget.TextView resource-id="br.com.noticias:id/adapter_editoria_news_editoria_indicator">
<android.widget.ImageView content-desc="imagem da noticia" resource-id="br.com.noticias:id/adapter_editoria_news_image">
<android.widget.LinearLayout>
<android.widget.TextView resource-id="br.com.noticias:id/adapter_editoria_news_title">
<android.widget.LinearLayout resource-id="br.com.noticias:id/adapter_editoria_layout">
<android.widget.TextView resource-id="br.com.noticias:id/adapter_editoria_news_editoria_indicator">
<android.widget.ImageView content-desc="imagem da noticia" resource-id="br.com.noticias:id/adapter_editoria_news_image">
<android.widget.LinearLayout>
<android.widget.TextView resource-id="br.com.noticias:id/adapter_editoria_news_title">
I expected that this LitView returns me 4 WebElements but it's return 1.
List<MobileElement> listNews = driver.findElements(By.id("br.com.noticias:id/editoria_listview"));
int size = listNews.size();
System.out.println(size);
What am I doing wrong? I also try with this code:
java.util.Iterator<MobileElement> i = listNews.iterator();
while(i.hasNext()) {
MobileElement row = i.next();
System.out.println(row.getTagName());
}
I also try using WebElement instead of MobileElement. The result is the same.
Upvotes: 1
Views: 458
Reputation: 36
It's because you are using a unique ID such that "br.com.noticias:id/editoria_listview" only has one element. Now I'm not sure if if you're looking for the title of the news but if you are you can use this ID: "br.com.noticias:id/adapter_editoria_news_title" which should return 4 elements.
Upvotes: 2