Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Selenium 2.0中对动态菜单项执行鼠标单击鼠标悬停_Java_Selenium_Selenium Webdriver - Fatal编程技术网

Java 如何在Selenium 2.0中对动态菜单项执行鼠标单击鼠标悬停

Java 如何在Selenium 2.0中对动态菜单项执行鼠标单击鼠标悬停,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我正在使用SeleniumWebDriver开发沃尔玛自动化。我编写了一个函数,将鼠标悬停在“家庭、家具和庭院”的“部门”菜单上,使其突出显示,然后单击“设备”链接。下面是我编写的函数,但它似乎没有悬停在元素上 public void NavigateDepartments(){ WebElement ApplianceLink = driver.findElement(By.xpath("//*[div='Home, Furniture & Patio']"))

我正在使用SeleniumWebDriver开发沃尔玛自动化。我编写了一个函数,将鼠标悬停在“家庭、家具和庭院”的“部门”菜单上,使其突出显示,然后单击“设备”链接。下面是我编写的函数,但它似乎没有悬停在元素上

    public void NavigateDepartments(){
        WebElement ApplianceLink = driver.findElement(By.xpath("//*[div='Home, Furniture & Patio']"));
    Actions myMouse = new Actions(driver);
        myMouse.moveToElement(ApplianceLink).build().perform();
    ApplianceLink.click();

}
我也试着给你一个绝对路径 Xpath(“/html/body/div/div/div[3]/div/div/ul/li[3]/div/div”)来查找元素,但它也不起作用。我遗漏了什么吗?

您应该首先将鼠标悬停在主菜单上,然后移动到新元素

WebElement menu = driver.findElement(By.xpath("//path to *appliance*"));
WebElement parentMenu = driver.findElement(By.xpath("//*[div='Home, Furniture & Patio']"));
Actions builder = new Actions(driver);
builder.moveToElement(parentMenu).moveToElement(menu).click().build().perform();

什么驱动程序版本和浏览器版本?