找不到子菜单元素,当鼠标指针移出菜单框架时,子菜单元素就会消失


我的代码是:
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

单击主菜单时出现子菜单。

有人可以帮助我在这里,如何找到所需的子菜单元素?

要使用只在悬停时出现的下拉菜单,必须使用:

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