如何使selenium server 2.0识别将鼠标悬停在菜单按钮上时出现的子菜单按钮。例如,有一个菜单按钮。将鼠标悬停在其上时,会出现2个子菜单按钮。我想点击子菜单按钮。如何让selenium server 2.0识别子菜单按钮并单击它?
答案 0 :(得分:1)
通过更新findElement方法的参数值来尝试以下代码:
//Find the main menu element
WebElement menu = driver.findElement(By.id("top_sell"));
//Perform mouse over action
Actions mouseMenu = new Actions(driver);
mouseMenu.moveToElement(menu).build().perform();
//Then find the sub menu element
WebElement subMenu = driver.findElement(By.cssSelector("a[href='/some_link'"));
//Now click on sub menu
subMenu.click();