java - 更新了问题 - 尽管放入了 try catch,但获取过时的元素异常,等到异常元素可见
问题描述
*我stale element Exception
在这部分得到了一个:
我从表中获取 id
这是导致陈旧元素的部分:
latestId.click();
我试过:使用下面的代码:
WebDriverWait wait = new WebDriverWait(driver,10);```
wait.until(ExpectedConditions.refreshed(ExpectedConditions.stalenessOf(latestId)));
基本上在方法中,因为 id.click() 和 createdvalue("id",latestid.gettexxt()) 都存在它导致问题。
我能得到一个解决方案吗..如果需要可以添加更多信息*
解决方案
您尚未共享元素的 ID 查找代码。
我建议你这样做:
- 通过其已知 ID 再次查找该元素。
- 等待元素可点击
- 点击它
代码:
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement myElement = wait.until(ExpectedConditions.elementToBeClickable(By.id("TheID")));
try {
Actions builder = new Actions(browser);
builder.moveToElement(myElement).click().build().perform();
} catch (Exception x1) {
myElement.click();
}
推荐阅读
- react-native - react native jitsi meet wrapper 让我的应用程序发生冲突
- networking - WebRTC 组播可以在本地网络中使用吗?
- javascript - 将 vue 3 中插槽内的事件处理程序传递给子组件
- javascript - 如何使用客户端 javascript 验证节点 js cookie
- postgresql - 获取视图的最后修改日期
- html - 从 span 和 li 标签添加额外的空间
- flutter - Dart 中的函数内部是否需要使用下划线 (_) 变量?
- angular - 离子应用程序启动时如何打开网页视图?
- pyspark - Pyspark - 如何在读入 pyspark 数据帧时根据文件名中的正则表达式模式过滤掉 .gz 文件
- rust - 如何解决传递给闭包的 &PathBuf 冲突的生命周期要求?