我是新的硒web驱动程序,但已成功地使用它到目前为止已经写了几个Junit测试。我现在正在进行第三次测试,并遇到无法找到元素的问题。我收到来自Selenium的错误“NoSuchElementException
”。我花了几个小时尝试很多选择(见下文)。硒WebDriver不识别元素,尝试了很多选择
简而言之,我测试的产品是第三方产品,确切地说,它与Google云端存储相连接。提供问题的页面实际上是Google编写的一个页面,所以我无法与开发人员交谈,以查看是否使用了框架,并且我无法从HTML中知道,但是存在一个称为“框架代码”的灰色部分,因此可能存在帧? (见下文)。
我曾尝试指定使用“driver.switchTo().frame(0);
”
有一个iframe
但也不能工作。
最后,我试图找到的元素在加载页面时会立即变灰。我试过了一个隐含的等待, “driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
”
但这并没有帮助。
任何关于我可能会做错的建议或更多建议尝试将不胜感激。我不能让这打败我。 :-)
这里是我尝试过的所有选项。注意第一个选项来自IDE,并且它在IDE中正常工作,而不是通过WebDriver。
`driver.findElement(By.id("submit_approve_access")).click();
driver.findElement(By.xpath("(//a[contains(text(),'Accept')])")).click();
driver.findElement(By.name("submit_access")).click();
driver.findElement(By.className("goog-buttonset-action")).click();
driver.findElement(By.cssSelector("input[name=submit_name]")).click();
driver.findElement(By.cssSelector("a[class='goog-buttonset-action']")).click();
driver.findElement(By.linkText(“Accept”)).click();
driver.findElement(By.xpath("//a[@class='goog-buttonset-action']")).click();
driver.findElement(By.xpath("//a[text() = ‘Accept]”)).click();
driver.findElement(By.cssSelector("button[type='submit']")).click();
driver.findElement(By.cssSelector("button[tabindex='1']")).click();`
下面是从页面的HTML(注意:我要找的就行*表示的元素我也尝试了一些从它上面的线,以及隐藏的项目):
`
<head></head>
<body>
<noscript></noscript>
<!--
framebuster code starts here
-->
<style></style>
<script></script>
<xmp style="display:none"></xmp>
<!--
framebuster code ends here
-->
<div id="ogb"></div>
<div id="third_party_info_container">
<div id="third_party_info" class="section_container" data-section="main">
<div class="column"></div>
<div id="approval_container">
<div class="column">
<div id="connect_container" class="modal-dialog-buttons button_container">
<form id="connect-approve" style="display: inline;" method="POST" action="https://accounts.google.com/o/oauth2/approval?as=32b8da86447…d=none&xsrfsign=APsBz4gAAAAAVLBpqOjvhQOwuPvNvPdcZF53EntxeTvP">
<input id="bgresponse" type="hidden" name="bgresponse"></input>
<input id="_utf8" type="hidden" value="☃" name="_utf8"></input>
<input id="state_wrapper" type="hidden" value="CoYDcmVzcG9uc2VfdHlwZT1jb2RlJmFjY2Vzc190eXBlPW9mZmxpbmUmcmVk…UucmVhZF9vbmx5EhUxMTY5MjAyNTM4Nzc2NTMxNzA1MTQY7seC5-zsnJbqAQ" name="state_wrapper"></input>
<input id="submit_access" type="hidden" value="" name="submit_access"></input>
*<button id="submit_approve_access" class="goog-buttonset-action" tabindex="1" type="submit"></button>
<button id="submit_deny_access" tabindex="2" type="submit"></button>
</form>
<div class="clear"></div>
</div>
</div>
</div>
</div>
</div>
<div style="display:none"></div>
<div id="tooltip_bubble"></div>
<script type="text/javascript"></script>
<iframe src="https://clients5.google.com/pagead/drt/dn/" aria-hidden="true" style="display: none;"></iframe>
</body>
`
您是否尝试过使用WebDriverWait进行显式等待? – alecxe
感谢@alecxe,使用WebDriverWait我得到一个超时。硒只是看不到按钮。尽管所有的帮助,我仍然感到困惑,但我已经了解了更多有关硒的知识。 – 3Dee