Bil*_*riy 2 java selenium selenium-webdriver
我试图在页面上找到要点击的链接:
<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>
Run Code Online (Sandbox Code Playgroud)
Java代码:
driver.findElement(By.xpath(".//*[@id='folder0']/span[2]")).click();
Run Code Online (Sandbox Code Playgroud)
但是驱动程序找不到元素:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":".//*[@id='folder0']/span[2]"}
Run Code Online (Sandbox Code Playgroud)
谢谢你的所有答案.我找到了解决问题的方法.最后一个命令是与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");
Run Code Online (Sandbox Code Playgroud)
所以我在IFrame实际上是因为它找不到任何元素.我执行了以下命令:
driver.switchTo().defaultContent();
Run Code Online (Sandbox Code Playgroud)
之后,可以找到定位器.
| 归档时间: |
|
| 查看次数: |
21008 次 |
| 最近记录: |