gpt4 book ai didi

java - 我无法使用 driver.findElement(By.xpath()); 找到具有 xpath 的 Web 元素

转载 作者:行者123 更新时间:2023-12-02 07:52:22 24 4
gpt4 key购买 nike

我试图在页面上找到要单击的链接:

<a id="folder0" class="js-folder icon-wrap icon-wrap_left menu__item__link menu__item__link_act menu__item__link_unread" href="/messages/inbox" rel="history">
<span class="js-folder-b-unread js-folder-unread menu__item__link__qnt">7</span>
<i class="js-folder-ico icon icon_left icon_folders icon_inbox_act"></i>
<span class="menu__item__link__text menu__item__link__text_linear">Input</span>
</a>

Java代码:

driver.findElement(By.xpath(".//*[@id='folder0']/span[2]")).click();

但是驱动程序无法找到该元素:

 org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":".//*[@id='folder0']/span[2]"}

最佳答案

感谢您的所有回答。我找到了解决我的问题的方法。最后一个命令是与 IFrame 链接的命令

WebElement editorFrame = driver.findElement(By.cssSelector("#sentmsgcomposeEditor_ifr"));
driver.switchTo().frame(editorFrame);

WebElement body1 = driver.findElement(By.tagName("body"));
body1.sendKeys(Keys.CONTROL + "a");

所以我实际上在 IFrame 中,因为它我找不到任何元素。我执行了以下命令:

 driver.switchTo().defaultContent();

之后就可以找到定位器。

关于java - 我无法使用 driver.findElement(By.xpath()); 找到具有 xpath 的 Web 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18531811/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com