java - DOM 中不再存在缓存的元素
问题描述
就像在类似的问题中一样,我使用 appium + java。尝试选择元素
在移动应用程序中,我转到页面,然后有许多元素 android.widget.ImageView(0),我需要选择 6 个(例如)这样的元素并执行其他步骤。字节只能选择一个元素,然后得到这样的异常:
org.openqa.selenium.StaleElementReferenceException: Cached elements 'By.id: com.company:id/selector_view' do not exist in DOM anymore
public GalleryPage choosePhotosFromAlbum(int count) {
List<MobileElement> photos = driver.findElementsById(elements.get("photo from gallery album selector"));
for (int i = 0; i < count; i++) {
photos.get(i).click();
}
return new GalleryPage(device);
}
解决方案
您可以使用显式等待来解决此问题。
public GalleryPage choosePhotosFromAlbum(int count)
{
List<MobileElement> photos = driver.findElementsById(elements.get("photo from gallery album selector"));
for (int i = 0; i < count; i++)
{
new WebDriverWait(driver,10).until(ExpectedConditions.presenceOfAllElementsLocatedBy("Your object property"));
photos.get(i).click();
}
return new GalleryPage(device);
}
推荐阅读
- python - 如何解决检测到的循环引用
- python - 为使用 pygame 模块制作的 python 游戏文件创建可执行安装程序时出错
- javascript - 数据表中上传的行不受隐藏列的影响
- javascript - 在 PHP 和 JS 中查找字数的差异问题
- ruby-on-rails - Active Admin:如何在输入 active_admin rails 时应用搜索过滤器
- swift - 如何将 POST 值发送到 API?[迅速]
- go - GO 获取 K8S api 服务器健康状态
- python - 将 python 函数转换为 pyspark lambda 函数
- arrays - 如何将所有素数放入C中的数组中
- tensorflow - 如何在 tf.keras 中修复这个 AssertionError?