How to Perform Mouse Over action using Selenium WebDriver?

package pkg_selenium;

import java.util.concurrent.TimeUnit;

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

public class MouseOverAction {

public static WebDriver driver;
public static void main(String[] args)throws Exception{
// TODO Auto-generated method stub

// Initialize WebDriver

driver = new FirefoxDriver();

// Wait For Page To Load

driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

// Go to URL

driver.get("http://www.flipkart.com/");

// Maximize Window
driver.manage().window().maximize();

// Mouse Over On 'Men' link

Actions builder = new Actions(driver);
builder.moveToElement(driver.findElement(By.xpath("//div[@class='top-menu unit']//a/span[contains(text(),'Men')]"))).perform();

Thread.sleep(5000L);

// Wait For Page To Load

driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);

// Click on 'T-Shirts' link

driver.findElement(By.xpath("//div[@id='submenu_men']/div[2]/div/ul/li/a[contains(text(),'T-Shirts')]")).click();

// Close Driver

driver.close();


}

}

Comments

Popular posts from this blog

How to handle calendar or date picker using dynamic XPATH?

Encoding and Decoding in Selenium using Base64 Class of Java

Parallel Execution In TestNG Framework Using ThreadLocal Concept