无法找到当鼠标指针移动到菜单框外时消失的子菜单元素

时间:2014-03-26 11:10:29

标签: java selenium-webdriver submenu

我的代码是:

driver.findElement(By.xpath(".//*[@id='fmf-name-title-cellsort-label']")).click(); // Main menu item
driver.findElement(By.xpath("//*[@id='quick-filter-input']")).sendKeys("Profile1121"); // Sub menu item

在上面的代码中:

移动移动时子菜单项消失,无法找到元素“@ id ='quick-filter-input”

显示错误:

org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//*[@id='quick-filter-input']"}
Command duration or timeout: 10.02 seconds

单击主菜单时会出现SubMenu。

有人可以帮助我,如何找到所需的subMenu元素?

1 个答案:

答案 0 :(得分:0)

要使用仅在悬停时出现的下拉列表,您必须使用:

Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(menu)); //this makes your submenu appear
actions.moveToElement(driver.findElement(submenu)).click().perform(); //this click your submenu or you can do whatever action you want with it