我真的很难与这个元素互动。我使用FirePath
,Selenium IDE和手动构建XPATH无济于事。我试图与" Group Accident"进行互动。我可以让Selenium发现"意外"使用driver.findElement(By.xpath("//div[@id='manage_area']/ul/li/div")).click();
我希望能够打开菜单并选择"添加或查看计划/选项"来自集体意外。 http://i.imgur.com/gHMaXLl.jpg
请帮忙!感谢。
这是我的代码:
@Test
public void testAddEEBenefitsinCOLO() throws Exception {
driver.get(baseUrl + "/bcs/stored.asp");
driver.findElement(By.id("TBUserName")).clear();
driver.findElement(By.id("TBUserName")).sendKeys("test");
driver.findElement(By.name("TBPassword")).clear();
driver.findElement(By.name("TBPassword")).sendKeys("pw1");
driver.findElement(By.name("Login")).click();
Thread.sleep(2000);
driver.findElement(By.name("TBPARAM")).click();
driver.findElement(By.name("TBPARAM")).clear();
driver.findElement(By.name("TBPARAM")).sendKeys("colo1973");
driver.findElement(By.name("TBPARAM")).sendKeys(Keys.ENTER);
driver.findElement(By.id("QRY")).click();
driver.findElement(By.id("QRY")).clear();
driver.findElement(By.id("QRY")).sendKeys("Melvin");
driver.findElement(By.name("B1")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//div[@id='manage_area']/ul/li/div[2]")).click();
Thread.sleep(1000);
错误讯息:
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//div[@id='manage_area']/ul/li/div[2]"}
Command duration or timeout: 30.01 seconds
HTML:
<div class="spAbove">
</div>
<div class="tableholder" id="ben110119014" style="width: 99%">
<form method="post" id="submitform110119014" action="EnrollChange.asp" name="ACCIDENT"
onsubmit="JavaScript: return validateChangeType(this); ">
<input type="hidden" name="TARGET" value="110119014" />
<h3>
<span onmouseover="javascript:showtip('BC110119014')">
Accident
</span>
<div id="manage_area" style="margin-left: -5px; visibility: hidden; display: inline;">
<a href="javascript:spawn_window('glossary.asp?PPVS=COLO1973#0','600','800','',0)"
title="What's this?">
<img src="images/help.gif" border="0"></a>
</div>
</h3>
<table class="textNormal sp" width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="tdata" valign="middle">
<input type="hidden" name="CHANGETYPE" id="Hidden1" value="0" />
<div id="manage_area">
<ul class="menuUL opMenu" title="Click here to view your options">
<li class="menuLI width225">
<div class="titleCell optImg" title="Click here to view your options">
<ul class="menuUL MainOptSubMenu">
<li class="menuLI"><a href="javascript: submitBenefit('16', 'submitform110119014'); "
value="16">
Add: Initial Population</a></li>
<li class="menuLI"><a href="javascript: submitBenefit('46', 'submitform110119014'); "
value="46">
Decline Benefit: (Prompt Effective)</a></li>
<li class="menuLI"><a href="javascript: submitBenefit('81', 'submitform110119014'); "
value="81">
Add or View Plan/Options</a></li>
<li class="menuLI"><a href="javascript: submitBenefit('64', 'submitform110119014'); "
value="64">
Decline Benefit</a></li>
</ul>
</div>
</li>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<p align="right" class="backtotop">
<a href="#PAGETOP">To Top</a></p>
<input type="hidden" name="TRANSID" value="5327418">
<input type="hidden" name="PPVS" value="COLO1973">
<input type="hidden" name="HST" value="SITE,BENEFITS,">
<input type="hidden" name="PF" value="BENEFITS">
<input type="hidden" name="SK" value="140062328">
<input type="hidden" name="BENCAT" value="ACCIDENT">
<input type="hidden" name="CANCHANGE" value="">
</form>
<div class="tableholder" id="ben167876400" style="width: 99%">
<form method="post" id="submitform167876400" action="EnrollChange.asp" name="GRPACC"
onsubmit="JavaScript: return validateChangeType(this); ">
<input type="hidden" name="TARGET" value="167876400" />
<h3>
<span onmouseover="javascript:showtip('BC167876400')">
Group Accident
</span>
<div id="manage_area" style="margin-left: -5px; visibility: hidden; display: inline;">
<a href="javascript:spawn_window('glossary.asp?PPVS=COLO1973#0','600','800','',0)"
title="What's this?">
<img src="images/help.gif" border="0"></a>
</div>
</h3>
<table class="textNormal sp" width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="tdata" valign="middle">
<input type="hidden" name="CHANGETYPE" id="Hidden1" value="0" />
<div id="manage_area">
<ul class="menuUL opMenu" title="Click here to view your options">
<li class="menuLI width225">
<div class="titleCell optImg" title="Click here to view your options">
<ul class="menuUL MainOptSubMenu">
<li class="menuLI"><a href="javascript: submitBenefit('16', 'submitform167876400'); "
value="16">
Add: Initial Population</a></li>
<li class="menuLI"><a href="javascript: submitBenefit('46', 'submitform167876400'); "
value="46">
Decline Benefit: (Prompt Effective)</a></li>
<li class="menuLI"><a href="javascript: submitBenefit('81', 'submitform167876400'); "
value="81">
Add or View Plan/Options</a></li>
<li class="menuLI"><a href="javascript: submitBenefit('64', 'submitform167876400'); "
value="64">
Decline Benefit</a></li>
</ul>
</div>
</li>
</ul>
</div>
</td>
</tr>
</tbody>
</table>
</div>
答案 0 :(得分:1)
你可以尝试
driver.findElement(By.linkText("Add or View Plan/Options")).click();
或
driver.findElement(By.xpath("//a[contains(.,'Add or View Plan/Options')]")).click();
答案 1 :(得分:0)
根据HTML代码段,由于“添加或查看/计划选项”出现在上面的2个表单中,因此下面是点击“管理权益”下的单击的方式“”群体意外“ :
1-使用此代码点击“群体意外”的“管理权益”按钮,以便下拉列表可见:
driver.findElement(By.xpath("//form[@id='submitform167876400']//ul[@class='menuUL opMenu']")).click();
2-点击其下方的“添加或查看/计划选项”子菜单项。
driver.findElement(By.xpath("//form[@id='submitform167876400']//a[contains(text(),'Add or View Plan/Options')]")).click();