首页 > 解决方案 > 尽管能够断言相同的元素,但无法找到元素

问题描述

当页面成功导航到新页面时,我能够断言一个元素(存在于导航的新页面上),但是当尝试“单击”面临与“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')]

标签: selenium-webdriver

解决方案


推荐阅读