How to mouse hover using java through selenium-webdriver and Java

To Mouse Hover over Electornics menu and select Camera & Photo you can use the following code block :

driver.get("http://demo.nopcommerce.com/");
Actions act = new Actions(driver);
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement electronics = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//li/a[@href="https://stackoverflow.com/electronics"]")));
act.moveToElement(electronics).perform();
WebElement camera_n_photo = driver.findElement(By.xpath("//li/a[@href="https://stackoverflow.com/electronics"]//following::ul/li/a"));
camera_n_photo.click();
System.out.println("Camera & photo Clicked.");

Leave a Comment