我在页面上有2个表格。两个表都包含一个名为Payment的链接:
<table class='topMenu' cellpadding='0' cellspacing='0'>
<tr class='null'>
<td>
<a class='logoClient' href="http://www.txtag.org" target="_blank">
<img class='imgNoBorder' src='/Violation/Images/logos/logo-client.gif' />
</a>
</td>
<td class='iconBox'>
<a href="#" accesskey='S' class="iconSearchLink" onfocus="javascript:nav('login/secure/loadSearch.action?validate=n&cmd=clearsearch&', 'Search-act')">
<u>S</u>earch</a>
</td>
<td class='iconBox'>
<a href="#" accesskey='E' class="iconEnrollLink" onfocus="javascript:nav('enroll.do?cmd=goto&type=reg&', 'Enrollment-reg')">
<u>E</u>nroll</a>
</td>
<td class='iconBox'>
<a href="#" accesskey='C' class="iconContactLink" onfocus="javascript:navCheckAcct('searchNoteHistory.do', 'Contact-not')">
<u>C</u>ontact</a>
</td>
<td class='iconBox'>
<a href="#" accesskey='H' class="iconHistoryActive" onfocus="javascript:navCheckAcct('sysTran.do?cmd=gotoRefSch&updateDate=07-12-12', 'History-act')">
<u>H</u>istory</a>
</td>
<td class='iconBox'>
<a href="#" accesskey='P' class="iconPaymentLink" onfocus="javascript:navCheckAcct('searchPaymentAccount.do','Payment-pay')">
<u>P</u>ayment</a>
</td>
<td class='iconBox'>
<a href="#" accesskey='A' class="iconAccountLink" onfocus="javascript:navCheckAcct('account.do','Account-inf')">
<u>A</u>ccount</a>
</td>
<td class='iconBox'>
<a href="#" accesskey='I' class="iconInventoryLink" onfocus="javascript:nav('inventoryReconcile.do?cmd=goto&cancel=yes','Inventory-rec')">
<u>I</u>nventory</a>
</td>
<td class='iconBox'>
<a href="#" accesskey='M' class="iconImgProcLink" onfocus="javascript:nav('supervisorReview.do?cmd=goto', '')">I<u>m</u>age</a>
</td>
<td class='iconBox'>
<a href="#" class="iconReportDisabled">
<u>R</u>eports</a>
</td>
<td class='iconBox'>
<a href="#" accesskey='L' class="iconLogoutLink" onfocus="javascript:nav('logout.do?cmd=logout', '')">
<u>L</u>og Out</a>
</td>
<td class='logoCompanyImage200'>
<img class='imgNoBorder' src='/Violation/Images/logos/logo-company.gif' />
</td>
</tr>
</table>
<table class='subMenu' cellpadding='0' cellspacing='0'>
<tr>
<td>
<ul class="lavaLampWithImage" id="1">
<li class="doesnotexist"/>
<a style="cursor: hand; " onClick="javascript:navCheckAcct('gotoTollMit.do', 'History-tol')">Tag Tolls</a>
</li>
<li class="doesnotexist"/>
<a style="cursor: hand; " onClick="javascript:navCheckAcct('gotoMitigation.do', 'History-vio')">Image Tolls</a>
</li>
<li class="doesnotexist"/>
<a style="cursor: hand; " onClick="javascript:nav('paymentHistory.do?cmd=feeHistory', 'History-fee')">Fees</a>
</li>
<li class="current"/>
<a style="cursor: hand; " onClick="javascript:navCheckAcct('sysTran.do?cmd=goto', 'History-act')">Activity</a>
</li>
<li class="doesnotexist"/>
<a style="cursor: hand; " onClick="javascript:navCheckAcct('history.do?cmd=status&', 'History-sta')">Status</a>
</li>
<li class="doesnotexist"/>
<a style="cursor: hand; " onClick="javascript:navCheckAcct('history.do?cmd=veh&', 'History-veh')">Vehicle</a>
</li>
<li class="doesnotexist"/>
<a style="cursor: hand; " onClick="javascript:navCheckAcct('history.do?cmd=tag&', 'History-tag')">Transponder</a>
</li>
<li class="doesnotexist"/>
<a style="cursor: hand; " onClick="javascript:navCheckAcct('history.do?cmd=demo&', 'History-dem')">Personal Info</a>
</li>
<li class="doesnotexist"/>
<a style="cursor: hand; " onClick="javascript:navCheckAcct('history.do?cmd=pay&', 'History-pay')">Payment</a>
</li>
<li class="doesnotexist"/>
<a style="cursor: hand; " onClick="javascript:navCheckAcct('history.do?cmd=stmt&', 'History-stm')">Statement</a>
</li>
<li class="doesnotexist"/>
<a style="cursor: hand; " onClick="javascript:navCheckAcct('bankruptcy.do?cmd=bankruptcy', 'History-ban')">Bankruptcy</a>
</li>
</ul>
</td>
</tr>
</table>
我正在尝试使用以下代码点击名为subMenu
的第二个表格中的付款链接:
//driver.findElement(By.xpath("//table[@class = 'subMenu']/tr[td[//a[contains(text(), 'Payment')]]]")).click();
当使用上面的代码时,程序不再抛出异常并指出无法找到该元素;但是,没有点击该链接。
答案 0 :(得分:0)
xpath的问题在于它返回了tr元素。我假设你想要链接元素。
尝试使用xpath:
//table[@class = 'subMenu']//a[contains(text(), 'Payment')]