我有firefox 23和webdriver 2.35以及以下代码点击上下文菜单工作正常,但我最近将firefox升级到版本31和webdriver到2.42,我无法点击上下文菜单
public static void clickTreeMenuItem(String treeNodeText, String menuItemText){
rightClickTreeNode(treeNodeText);
contextClick(menuItemText);
}
public static void rightClickTreeNode(String nodeText){
List<WebElement> treeNodes = driver.findElements(By.className("class-name"));
for(WebElement treeNode : treeNodes){
if(treeNode.getText().equals(nodeText)){
Actions builder = new Actions(driver);
Action rightClick = builder.contextClick(treeNode).build();
rightClick.perform();
}
}
}
public static void contextClick(String menuItem){
waitFor(ExpectedConditions.presenceOfAllElementsLocatedBy(By.className("x-menu-list-item")));
List<WebElement> allMenuItems = driver.findElements(By.className("x-menu-list-item"));
for(WebElement item : allMenuItems){
if(item.getText().equals(menuItem)){
item.click();
break;
}
}
}
上下文菜单的HTML源
<div class=" x-menu-list" style="height: 72px;">
<div id="x-menu-el-xx" class="x-menu-list-item ">
<span id="com.xx" class=" x-menu-item x-unselectable x-component" unselectable="on" style="color: black;">
New Item
</span>
</div>
当前行为:我看到右键单击发生并看到上下文菜单,但没有发生点击。我没有看到任何相关的例外,webdriver只是转向下一步..任何指针..?
答案 0 :(得分:0)
当我使用'x-menu-item'而不是使用'x-menu-list-item'时问题解决了
public static void contextClick(String menuItem){
waitFor(ExpectedConditions.presenceOfAllElementsLocatedBy(By.className("x-menu-item")));
List<WebElement> allMenuItems = driver.findElements(By.className("x-menu-item"));
for(WebElement item : allMenuItems){
if(item.getText().equals(menuItem)){
item.click();
break;
}
}
}