Click on html menu by selenium webdriver

selenium

This example will show how we can use selenium webdriver to open a menu

package com.webdriver_03;

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 MyMenu {

	public WebDriver driver;
	private String baseUrl;
	
	public static void main(String[] args){
		MyMenu mm = new MyMenu();
		mm.launch_browser();
	}
	public void launch_browser() {
		try{
			baseUrl = "http://www.autoitscript.com/site/autoit/downloads/";
			driver = new FirefoxDriver();
			driver.get(baseUrl); 
			WebElement parentMenu = driver.findElement(By.xpath(".//*[@id='menu-item-207']/a"));
			Actions act = new Actions(driver);
			act.moveToElement(parentMenu).build().perform(); 
			Thread.sleep(1000);
			driver.findElement(By.xpath(".//*[@id='menu-item-210']/a")).click();
			Thread.sleep(3000);
			driver.quit();
		}
		catch (Exception ex)
		{
			ex.getMessage();
		}
	}
}

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *