Single Post

Header

Sunday, November 1, 2015

How to handle Actions using Selenium WebDriver

Handle Actions using Selenium WebDriver

package SeleniumPractise;

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

public class ActionsHandle {
  
  @Test
  public void handleActions() throws InterruptedException {
    WebDriver driver = new FirefoxDriver();
    driver.get("http://docs.seleniumhq.org/");
    Thread.sleep(2000);
    WebElement element = driver.findElement(By.cssSelector("#menu_documentation a"));
    Actions act = new Actions(driver);
    // Right click on the web element
    act.contextClick(element).build().perform();
    Thread.sleep(2000);
    // Arrow down
    act.sendKeys(Keys.ARROW_DOWN).build().perform();
    Thread.sleep(2000);
    // Click on it
    act.sendKeys(Keys.ENTER).build().perform();
    Thread.sleep(2000);
    WebElement support = driver.findElement(By.cssSelector("#menu_support a"));
    // Double Click on an element
    act.moveToElement(support).doubleClick().perform();
    Thread.sleep(2000);
    driver.close();
  }

}

No comments:

Post a Comment