user1028428
user1028428

Reputation: 81

How can I perform mouse click on Mouse Hover of Dynamic Menu items in Selenium 2.0

I am working on Walmart automation using Selenium WebDriver. I have written a function to hover over the Departments Menu "Home , Furniture & Patio" so that it gets highlighted and I can click on "Appliances" link. Here is the function that I have written but it does not seem to hover over the element.

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

}

I also tried giving absolute path for Xpath("/html/body/div/div/div[3]/div/div/div/ul/li[3]/div/div") to find the element and it did not work either. Am I missing anything ?

Upvotes: 0

Views: 3398

Answers (1)

Stéphane Piette
Stéphane Piette

Reputation: 5421

You should first hover on the main menu, then move to the new element

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

Upvotes: 2

Related Questions