【问题标题】:How can I perform mouse click on Mouse Hover of Dynamic Menu items in Selenium 2.0如何在 Selenium 2.0 中的动态菜单项的鼠标悬停上执行鼠标单击
【发布时间】:2013-03-06 17:26:23
【问题描述】:

我正在使用 Selenium WebDriver 进行沃尔玛自动化。我编写了一个函数来将鼠标悬停在部门菜单“家庭、家具和露台”上,以便突出显示它,然后我可以单击“电器”链接。这是我编写的函数,但它似乎没有悬停在元素上。

    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/div/ul/li[3]/div/div") 找到元素,它也没有工作。我错过了什么吗?

【问题讨论】:

  • 什么驱动版本和浏览器版本?

标签: java selenium selenium-webdriver


【解决方案1】:

你应该先悬停在主菜单上,然后移动到新元素

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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多