我可以遍历菜单项,但WebDriver不会点击最终元素。
我的代码段:
WebElement hover0 = driver.findElement(By.id("td_Menu_0"));
WebElement hover = driver.findElement(By.xpath(".//*[@id='role6_Maintain']/table/tbody/tr/td[1]"));
action.moveToElement(hover0).moveToElement(hover);
action.moveToElement(driver.findElement(By.cssSelector("#menuClickable_0_6_0_0")))
.click().build().perform();
最终的WebElement
HTML:
<td onkeydown="return menuClickableOperation(this,event);"
onclick="javascript:deleteGrpWindowNode('menu_Maintain',0,'br_w_BusissPartner','BRGUI','Business Partner','','','HJHF');"
onmouseout="menuDeSelect(this);" onmouseover="menuSelect(this)"
onmousemove="DisplayIFrame();" tabindex="11" id="menuClickable_0_6_0_0"
class="menuNormal2">
<table width="100%">
<tbody>
<tr>
<td width="100%" style="">
<p title="Business Partner" class="MenuTxt">Business Partner</p>
</td>
</tr>
</tbody>
</table>
</td>
答案 0 :(得分:0)
请尝试使用此代码:
action.moveToElement(hover0).build().perform();
action.moveToElement(hover).build().perform();
new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#menuClickable_0_6_0_0")));//Waiting for 20 seconds for the final element to be visible.
action.moveToElement(driver.findElement(By.xpath("//td[@id='menuClickable_0_6_0_0']//p[.='Business Partner']"))).click().build().perform();
答案 1 :(得分:0)
由于你已经在hover0上盘旋并悬停,我希望第三个对象可用。 那么为什么你不能直接点击第三个对象,如
driver.findElement(By.xpath("//td[@id='menuClickable_0_6_0_0']//p[.='Business Partner']").click
另一种方式就是
action.click(yourElement).build().perform()