gpt4 book ai didi

java - 没有在 Selenium + Appium 上获取动态 ListView 的所有元素

转载 作者:行者123 更新时间:2023-11-29 19:07:38 25 4
gpt4 key购买 nike

我的 Android apk 中有这个动态 ListView:

<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">

我预计此 LitView 会返回 4 个 WebElements,但它返回了 1 个。

List<MobileElement> listNews = driver.findElements(By.id("br.com.noticias:id/editoria_listview"));

int size = listNews.size();
System.out.println(size);

我做错了什么?我也尝试使用此代码:

 java.util.Iterator<MobileElement> i = listNews.iterator();
while(i.hasNext()) {
MobileElement row = i.next();
System.out.println(row.getTagName());
}

我也尝试使用 WebElement 而不是 MobileElement。结果是一样的。

最佳答案

这是因为您使用的是唯一 ID,因此“br.com.noticias:id/editoria_listview”只有一个元素。现在我不确定你是否正在寻找新闻的标题,但如果你是,你可以使用这个 ID:“br.com.noticias:id/adapter_editoria_news_title”应该返回 4 个元素。

关于java - 没有在 Selenium + Appium 上获取动态 ListView 的所有元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46594368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com