java - org.openqa.selenium.NoSuchElementException:在检查条件时,使用给定的搜索参数无法在页面上找到一个元素
问题描述
我正在编写一个 if 条件来查找项目中的元素位置。
if (!(driver.findElement(MobileBy.xpath(ObjRepoProp.getProperty("searchTextBox_XPATH"))).isDisplayed()
|| driver.findElement(MobileBy.xpath(ObjRepoProp.getProperty("routeOverview_XPATH"))).isDisplayed()
|| driver.findElement(MobileBy.xpath(ObjRepoProp.getProperty("scrollNavigationDrawer_XPATH")))
.isDisplayed())) {
throw new IllegalStateException("This is not Destination Input page");
}
在此代码中,如果条件之一为真,则“org.openqa.selenium.NoSuchElementException:使用给定的搜索参数无法在页面上找到元素”。触发器和测试用例失败。
解决方案
让我们首先了解这是如何工作的。
您的代码发生了两件事。
- 您正在尝试在网页上查找元素
- 拥有元素后,您将验证它是否可见。
因此,如果所有元素都在页面上找到并找到,那么只有它会起作用,否则你总是会得到NoSuchElementException
.
推荐阅读
- linux - 为什么 mount.cifs 不使用我的凭证文件?
- vaadin - 使用 vaadin 应用程序时未显示插槽
- r - 如何缩短不同日期的多个时间序列?
- elasticsearch - 在 Elasticsearch 的对象类型属性/字段中应用语言分析器
- tensorflow - 如何在 Tensorflow 中验证和分配 GPU 分配?
- java - Jackson fasterxml UnrecognizedPropertyException 随机发生
- angular - Angular 7:限制导航以防止浏览器挂起
- html - 为什么css不透明度淡出不起作用
- python - 带字符串参数的 max() 函数
- git - 我可以在同一命令行中推送到两个远程存储库吗?