我使用硒的webdriver 2.41.0在Win 7与Internet Explorer 11和有麻烦点击“我的申请”链接没有这样的元素例外。 HTML貌似到目前为止,我已经试过这的超链接
<html class="ltr" dir="ltr">
<head>
<body class="navigator ">
<div class="nav-wrapper">
<div id="div.c16bf8b2089e8100af3b7af3edb7aefd" class="app_menu_div" style="display: block;" sclabel="false" extinct="true" appid="c16bf8b2089e8100af3b7af3edb7aefd">
<span id="c16bf8b2089e8100af3b7af3edb7aefd" class="submenu" style="display:block;">
<table cellspacing="0" cellpadding="1" border="0" width="100%">
<tbody>
<tr id="module.dd9d893a089e8100af3b7af3edb7ae21" name="nav.module" moduleparent="c16bf8b2089e8100af3b7af3edb7aefd" moduletype="DIRECT" modulename="Dashboard" moduleid="dd9d893a089e8100af3b7af3edb7ae21">
<tr id="module.70fbfcf2089e8100af3b7af3edb7ae43" name="nav.module" moduleparent="c16bf8b2089e8100af3b7af3edb7aefd" moduletype="LIST" modulename="Workspace" moduleid="70fbfcf2089e8100af3b7af3edb7ae43">
<tr id="module.6b7b70f2089e8100af3b7af3edb7ae2c" name="nav.module" moduleparent="c16bf8b2089e8100af3b7af3edb7aefd" moduletype="DIRECT" modulename="Request" moduleid="6b7b70f2089e8100af3b7af3edb7ae2c">
<tr id="module.8eb40db6089e8100af3b7af3edb7ae75" name="nav.module" moduleparent="c16bf8b2089e8100af3b7af3edb7aefd" moduletype="LIST" modulename="My Requests" moduleid="8eb40db6089e8100af3b7af3edb7ae75">
<td class="noWrap" colspan="2">
<img align="left" width="16" height="16" src="MyRequests_16.pngx"/>
<h3 class="nav_menu_header">
<a id="8eb40db6089e8100af3b7af3edb7ae75" class="menu" href="https://clouddev.service-now.com/sc_request_list.do?sysparm_userpref_module=8eb40db6089e8100af3b7af3edb7ae75&sysparm_query=active=true^opened_by=javascript:gs.getUserID()^EQ" data-cancelable="true" target="gsft_main" style="">My Requests</a>
</h3>
</td>
</tr>
</tbody>
</table>
</span>
</div>
</body>
</html>
代码是这样
WebElement myReq = driver.findElement(By.partialLinkText("My Requests"));
myReq.click();
driver.findElement(By.xpath("//a[contains(text(), My Requests)]")).click();
driver.findElement(By.xpath("html/body/div[1]/span/table/tbody/tr[4]/td/h3/a")).click();
对于上述所有的选项,我得到的
NoSuchElementException异常:无法找到使用XPath元素
任何其他选项,我可以试试吗?
感谢
谢谢布佩希,我不认为这是一个iFrame(似乎无法找到它的HTML),但试图通过使用 '驱动切换,按您的建议.switchTo()帧( “gsft_nav”);' ,得到了以下 'org.openqa。 selenium.NoSuchFrameException:找不到框架(警告:服务器没有提供任何堆栈跟踪信息)' – r0b0t99 2014-11-02 22:39:19
我还发现以下代码可以在主/登录页面 'driver.switchTo().frame(“gsft_nav”)中正常工作;' 'WebElement myReq = driver.findElement(By.linkText( “我的请求”));' 'myReq.click();' 但是,当我尝试从另一个页面执行相同的代码(请求被提交并且收到响应)它会抛出无帧发现异常。 页面,没有帧中找到异常被抛出看起来像这样在Firebug 任何想法? –
r0b0t99
2014-11-03 00:38:17
当你与你的登陆页面完成后,使用此行代码 driver.switchTo()。defaultContent(); 它会将焦点移出当前帧到webdriver。然后,当您移动到其他页面时,再次切换到该页面上的框架。我希望它能解决问题。 – Bhupesh 2014-11-03 03:25:08