Single Post

Header

Monday, February 8, 2016

Mouse Over and Click on Sub Menu link using Selenium WebDriver

Mouse Over and Click on Sub Menu link using Selenium WebDriver

import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class MouseOverAndClickSubMenu {


@Test
public void mouseOverAndClickSubMenu() throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("http://flex.apache.org/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
WebElement menu = driver.findElement(By.xpath(".//*[@id='nav']/li[2]/a"));
WebElement subMenu = driver.findElement(By.xpath(".//*[@id='nav']/li[2]/ul/li[5]/a"));
Actions act = new Actions(driver);
act.moveToElement(menu).perform();     // Mouse over an element
Thread.sleep(2000);
act.click(subMenu).perform();   // Click on a sub menu link
Thread.sleep(3000);
driver.quit();
}


}