Reputation: 81
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
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