Example usage for org.openqa.selenium.interactions Actions moveToElement

List of usage examples for org.openqa.selenium.interactions Actions moveToElement

Introduction

In this page you can find the example usage for org.openqa.selenium.interactions Actions moveToElement.

Prototype

public Actions moveToElement(WebElement target) 

Source Link

Document

Moves the mouse to the middle of the element.

Usage

From source file:com.webdriver1.MouseOver.java

public static void main(String[] args) throws InterruptedException {
    WebDriver driver = new FirefoxDriver();
    //maximize window
    driver.manage().window().maximize();
    //wait for page load
    driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
    //Go to URL/*from  ww w. ja v a 2s  . c om*/
    driver.get("http://flex.apache.org/");
    //Get web element
    WebElement element = driver.findElement(By.xpath("//ul[@id='nav']/li[2]/a"));
    //Thread.sleep(1000);
    //Get sub web element/html/body/div[1]/div[1]/
    WebElement element1 = driver.findElement(By.xpath("//a[contains(text(),'License & Trademarks')]"));
    //Declare Actions Object
    Actions action = new Actions(driver);
    //Mouse over on element items
    action.moveToElement(element).build().perform();
    //wait for items
    Thread.sleep(2000);
    //click on element1 items
    action.moveToElement(element1).clickAndHold().build().perform();

}

From source file:com.worldline.easycukes.selenium.pages.Page.java

License:Open Source License

/**
 * @param selector// w ww  . j av  a  2 s . c  om
 */
public void moveToElement(By selector) {
    final Actions builder = new Actions(driver);
    builder.moveToElement(getWebElement(selector)).perform();
    builder.release();
}

From source file:com.worldline.easycukes.selenium.pages.Page.java

License:Open Source License

public void moveToAndClick(By selector) {
    final Actions builder = new Actions(driver);
    builder.moveToElement(getWebElement(selector)).click().perform();
    builder.release();//from ww  w .  j av a 2  s .c  o m
}

From source file:com.xirrus.xms.locallib.NavigateTo.java

/**
 * Navigates to the specified XMS webpage.
 * /*from w ww .ja v  a 2 s  .c o  m*/
 * @mainPage Main panel xmstest:id getting from PATH properties file
 * @subPage Sub panel xmstest:id getting from PATH properties file
 * @throws InterruptedException
 */
public void goTo(String mainPage, String subPage) throws InterruptedException {
    App_Log.debug("Debug:" + " Navigating to " + mainPage + " " + subPage);
    Actions actions = new Actions(driver);
    // Move mouse to Monitor
    if (subPage == null) {
        driver.findElement(By.xpath("//a[@*='" + mainPage + "']")).click();
    } else {
        // Navigate to Overview Access Points (Monitor>>Access Points)
        actions.moveToElement(driver.findElement(By.xpath("//a[@*='" + mainPage + "']")))
                .moveToElement(driver.findElement(By.xpath("//a[@*='" + subPage + "']"))).click().build()
                .perform();
    }
    Thread.sleep(clickDelay);
}

From source file:day3.Day3task4.java

@Test
public static void hoverProducts() throws InterruptedException {
    Actions action = new Actions(getDriver());
    WebElement element = getDriver()//from w w w. j a  v  a 2s . com
            .findElement(By.xpath("html/body/div[1]/header/div[1]/div/div/div/div/nav/ul/li[1]/a"));

    action.moveToElement(element).build().perform();
    WebElement element1 = getDriver()
            .findElement(By.xpath("html/body/div[1]/header/div[1]/div/div/div/div/nav/ul/li[1]/ul/li[3]/a"));
    action.moveToElement(element1).build().perform();
    WebElement ele2 = getDriver().findElement(By
            .xpath("html/body/div[1]/header/div/div/div/div/div/nav/ul/li[1]/ul/li[3]/ul/li[6]/ul[2]/li[2]/a"));
    action.moveToElement(ele2).click(ele2).build().perform();
    WebElement ele3 = getDriver()
            .findElement(By.xpath("html/body/div[4]/header/div[1]/div/div/div/div/nav/ul/li[4]/a"));
    action.moveToElement(ele3).build().perform();
    WebElement element4 = getDriver().findElement(By.cssSelector(".dropdown-content_link.m-menu__a"));
    action.moveToElement(element4).build().perform();
    ((JavascriptExecutor) getDriver()).executeScript("arguments[0].click();", element4);

    //getDriver().findElement(By.xpath(" html/body/div[4]/header/div[1]/div/div/div/div/nav/ul/li[4]/ul/li[3]/a")).click();
    getDriver().findElement(By.id("email")).sendKeys("ankammarao@gmail.com");
    getDriver().findElement(By.id("license")).sendKeys("123456");
    getDriver().findElement(By.className("btn-thin-blue")).click();
    String actual = getDriver().findElement(By.xpath("html/body/div[1]/div[1]/div[2]/div/div/div/div"))
            .getText();
    String expected = "ERROR: Invalid e-mail or license number";
    Assert.assertEquals(actual, expected);

}

From source file:dhtml1.Dhtml.java

@Test
public void products() throws InterruptedException {
    Actions action = new Actions(driver);
    WebElement we = driver/*from  ww  w  .  j  ava 2  s.  co m*/
            .findElement(By.xpath("html/body/div[1]/header/div[1]/div/div/div/div/nav/ul/li[1]/a"));
    action.moveToElement(we).build().perform();
    WebElement we1 = driver
            .findElement(By.xpath("html/body/div[1]/header/div[1]/div/div/div/div/nav/ul/li[1]/ul/li[3]/a"));
    action.moveToElement(we1).build().perform();
    Thread.sleep(2000);
    driver.findElement(By.xpath(
            "html/body/div[1]/header/div[1]/div/div/div/div/nav/ul/li[1]/ul/li[3]/ul/li[6]/ul[2]/li[2]/a"))
            .click();
    driver.findElement(By.xpath("html/body/div[1]/header/div[1]/div/div/div/div/nav/ul/li[4]/a")).click();
    driver.findElement(By.xpath(".//*[@id='email']")).sendKeys("kishantejy12@gmail.com");
    driver.findElement(By.xpath(".//*[@id='license']")).sendKeys("kishantej");
    driver.findElement(By.xpath(".//*[@class='btn-thin-blue']")).click();
    String actualtext = driver.findElement(By.xpath(".//*[@class='submit-error m-bottom-30']")).getText();
    String expectedurl = "ERROR: Invalid e-mail or license number";
    Assert.assertEquals(actualtext, expectedurl);

}

From source file:edu.samplu.common.WebDriverLegacyITBase.java

License:Educational Community License

/**
 * {@link Actions#moveToElement(org.openqa.selenium.WebElement)}
 * @param by//  ww w .jav a  2s .c  o  m
 */
public void fireMouseOverEvent(By by) {
    Actions builder = new Actions(driver);
    Actions hover = builder.moveToElement(driver.findElement(by));
    hover.perform();
}

From source file:exercise.component.runner.java

public static void selectCategoryDropdown(String optionName) throws InterruptedException {

    WebElement category = driver.findElement(By.name("test"));
    java.util.List<WebElement> opts = category.findElements(By.tagName("option"));
    category.click();/*from   w w  w. ja va2  s.  co  m*/
    Iterator iter = opts.iterator();
    while (iter.hasNext()) {
        WebElement opt = (WebElement) iter.next();
        if (opt.getAttribute("value").equals(optionName)) {
            Actions act = new Actions(driver);
            act.moveToElement(opt).click().build().perform();
            //opt.click();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            break;
        }
    }

}

From source file:GlennsPack.GlennWebAPI.Bot2048.java

License:Open Source License

public Bot2048() {
    System.setProperty("webdriver.chrome.driver", "C:/Users/Glenn/Downloads/chromedriver/chromedriver.exe");
    WebDriver driver = new ChromeDriver();

    driver.manage().window().setSize(new Dimension(2000, 800));

    driver.get("http://annimon.github.io/16384/");

    //      try {
    //         Thread.sleep(2000);
    //      } catch (Exception e) {
    //         // FIXME: handle exception
    //      }/* w w w  . j a v a2 s .  c  o  m*/
    //      
    WebElement element = driver.findElement(By.xpath("/html/body/div"));
    //            ("/html/body/div/div[2]"));

    Actions actions = new Actions(driver);
    actions.moveToElement(element);
    actions.click();
    CharSequence[] array = { Keys.ARROW_DOWN, Keys.ARROW_LEFT, Keys.ARROW_RIGHT };
    for (int i = 0; i < 1000000; i++) {
        Random random = new Random();
        actions.sendKeys(array[random.nextInt(3)]);
        ;
        actions.sendKeys(Keys.ARROW_DOWN);
        actions.build().perform();
        try {
            //         Thread.sleep(1);
        } catch (Exception e) {
            // FIXME: handle exception
        }
    }
}

From source file:GlennsPack.GlennWebAPI.Keybr.java

License:Open Source License

public void runer(WebDriver driver) {

    driver.findElement(By.className("Tour-close")).click();

    System.out.println("CLICKED");
    ///*w  w w . j  a v a  2  s .  c o  m*/
    try {

        driver.findElement(By.id("Practice-textInput")).click();
        Thread.sleep(1000);
        WebElement element = driver.findElement(By.id("Practice"));

        Actions actions = new Actions(driver);
        actions.moveToElement(element);
        actions.click();

        String abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz[]-.,?!()\"'";

        Robot robot = new Robot();

        for (int i1 = 0; i1 < 30; i1++) {

            try {
                for (int i = 0; i < 200; i++) {

                    String currLetter = driver
                            .findElement(By.cssSelector("span.TextInput-item:nth-child(" + (i + 1) + ")"))
                            .getText();
                    System.out.println(currLetter);

                    if (!abc.contains(currLetter)) {
                        currLetter = " ";
                        System.out.println("SPACE");
                        i++;
                    }

                    Thread.sleep(25);

                    robot.keyPress(KeyEvent.getExtendedKeyCodeForChar(currLetter.charAt(0)));
                    actions.build().perform();
                    robot.keyRelease(KeyEvent.getExtendedKeyCodeForChar(currLetter.charAt(0)));
                }
            } catch (Exception e) {
                System.out.println("Another row done");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

}