selenium-webdriver - 尽管能够断言相同的元素,但无法找到元素
问题描述
当页面成功导航到新页面时,我能够断言一个元素(存在于导航的新页面上),但是当尝试“单击”面临与“NoSuchElementException”问题相同的元素时。
FAILED with exception
org.openqa.selenium.NoSuchElementException: no such
element: Unable to locate element: method: xpath,
selector:"//div...}
我尝试使用下面的代码查找此元素是否在 iframe 中,日志显示页面上不存在 iframe,同样的元素也可以成功断言。
List<WebElement> elements =
driver.findElements(By.tagName("iframe"));
log.info("elements iframe is" + elements);
日志显示:
elements iframe is[[[ChromeDriver: chrome on XP
(b39f02ba258fd8b71c77)] -> tag name:
iframe]]
通过强睡眠尝试,页面清楚地显示了这个元素,但总是得到 NoSuchElementException。
此元素的 HTML:
<div class="assign-button-text" xpath="1">Go and Attend</div>
路径:
//div[contains(text(),'Go and Attend')]
解决方案
推荐阅读
- css - 角表边框
- flutter - 如何在颤动中用 ThemeConsumer 包装 Drawer
- android - Android:RelativeLayout 禁用可点击的 Imageview 按钮
- java - REST API 的问题
- reactjs - Material-ui中显示popper时如何保持对输入字段的关注
- django - 在 Django rest 框架中用一个 URL 处理多个 ViewSet?
- mongodb - 启动后无法打开 PID 文件 /var/run/mongodb/mongod.pid(还没有?):符号链接级别太多 MongoDB Centos 7
- node.js - 在 Apache Cordova 中使用 Express 项目
- python-3.x - 有效数独:如何减少运行时间
- sql - sqlplus oracle11g 为什么sequence.nextval 在我第一次调用它时会自动增加值?