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, int xOffset, int yOffset) 

Source Link

Document

Moves the mouse to an offset from the center of the element.

Usage

From source file:cc.kune.selenium.SeleniumUtils.java

License:GNU Affero Public License

/**
 * Move mouse to.// ww  w.ja  v a2s. c om
 * 
 * @param webdriver
 *          the webdriver
 * @param element
 *          the element
 * @param xOffset
 *          the x offset
 * @param yOffset
 *          the y offset
 */
public static void moveMouseTo(final WebDriver webdriver, final WebElement element, final int xOffset,
        final int yOffset) {
    showCursor(webdriver, element, xOffset, yOffset);
    final Actions actions = new Actions(webdriver);
    actions.moveToElement(element, xOffset, yOffset);
    final Action action = actions.build();
    action.perform();
}

From source file:cc.kune.selenium.SeleniumUtils.java

License:GNU Affero Public License

/**
 * Move mouse to and click./* ww  w . ja  v  a2 s.co m*/
 * 
 * @param webdriver
 *          the webdriver
 * @param element
 *          the element
 * @param xOffset
 *          the x offset
 * @param yOffset
 *          the y offset
 */
public static void moveMouseToAndClick(final WebDriver webdriver, final WebElement element, final int xOffset,
        final int yOffset) {
    // showCursor(webdriver, element, xOffset, yOffset);
    final Actions actions = new Actions(webdriver);
    actions.moveToElement(element, xOffset, yOffset);
    actions.click();
    final Action action = actions.build();
    action.perform();
}

From source file:com.cengage.mindtap.keywords.StudyHubPageActions.java

public void selectText() {
    waitForElementPresent("highlighttext");
    WebElement element = driver.findElement(By.xpath(""));
    waitTOSync();/*from   w w w.j  a v a  2  s . c  o m*/
    // assuming driver is a well behaving WebDriver
    Actions actions = new Actions(driver);
    // and some variation of this:
    actions.moveToElement(element, 10, 5).clickAndHold().moveByOffset(30, 0).release().perform();
}

From source file:com.formkiq.web.WorkflowAddControllerIntegrationTest.java

License:Apache License

/**
 * Fill Signature.//  www  .  j av  a2 s.  c  om
 * @param datafieldid {@link String}
 */
private void fillSignature(final String datafieldid) {

    WebElement element = findElementBy("canvas", "data-fieldid", datafieldid);

    final int startXY = 50;
    Actions builder = new Actions(getDriver());
    Action drawAction = builder.moveToElement(element, startXY, startXY).clickAndHold()
            .moveByOffset(startXY, startXY).release().build();
    drawAction.perform();
}

From source file:com.ggasoftware.uitest.control.Element.java

License:Open Source License

/**
 * A convenience method that performs click at the location of the source element
 *
 * @param xOffset - horizontal move offset.
 * @param yOffset - vertical move offset.
 * @return Parent instance/*from www  . j  a va 2  s.com*/
 */
public ParentPanel clickBy(int xOffset, int yOffset) {
    doJAction(format("click element:  horizontal move offset- %dpx; vertical move offset- %dpx", xOffset,
            yOffset), () -> {
                Actions builder = new Actions(getDriver());
                Action click = builder.moveToElement(getWebElement(), xOffset, yOffset).click().build();
                click.perform();
            });
    return parent;
}

From source file:com.ggasoftware.uitest.control.Element.java

License:Open Source License

/**
 * Focus on the Element(WebElement)//from  ww w  . j av a  2 s. c o m
 *
 * @return Parent instance
 */
public ParentPanel focus() {
    Dimension size = getWebElement().getSize(); //for scroll to object
    logAction(this, getParentClassName(), "focus");
    Actions builder = new Actions(getDriver());
    org.openqa.selenium.interactions.Action focus = builder
            .moveToElement(getWebElement(), size.width / 2, size.height / 2).build();
    focus.perform();
    return parent;
}

From source file:com.ggasoftware.uitest.control.Elements.java

License:Open Source License

/**
 * Focus on the WebElement by index//from   w  w  w .  j  a  va  2 s.c  o m
 *
 * @param elementIndex - index of WebElement
 * @return Parent instance
 */
public ParentPanel focus(int elementIndex) {
    Dimension size = getWebElements().get(elementIndex).getSize(); //for scroll to object
    logAction(this, getParentClassName(), "Focus");
    Actions builder = new Actions(WebDriverWrapper.getDriver());
    org.openqa.selenium.interactions.Action focus = builder
            .moveToElement(getWebElements().get(elementIndex), size.width / 2, size.height / 2).build();
    focus.perform();
    return parent;
}

From source file:com.hotwire.test.steps.search.air.AirSearchModelWebApp.java

License:Open Source License

@Override
public void clickOutOfDisambiguationLayer() {
    AirSearchFragment airSearchFragment = new AirSearchFragment(getWebdriverInstance());
    Actions action = new Actions(getWebdriverInstance());
    action.moveToElement(airSearchFragment.getFareFinderForm(), 500, 500).click().perform();
}

From source file:com.ibm.watson.app.qaclassifier.selenium.MenuIT.java

License:Open Source License

@Ignore
@Test/*from   w  ww  .  ja v a 2 s  .  c o  m*/
public void clickMenuIconThenAwayFromMenuIconHidesMenuList() {
    WebElement menuIconContainer = driver.findElement(By.id("menuIconContainerDesktop"));
    WebElement menuIconImg = menuIconContainer
            .findElement(By.xpath(".//span[contains(concat(' ', @class, ' '), ' menuIconImg ')]"));

    // Clicking away from the menu icon should also close the menu
    menuIconImg.click();
    WebElement menuList = driver.findElement(By.tagName("menu-list"));
    assertTrue("After clicking the menu icon, the menu list is visible", menuList.isDisplayed());

    Actions action = new Actions(driver);
    action.moveToElement(driver.findElement(By.tagName("body")), 0, 0);
    action.click().build().perform();
    assertFalse("After clicking outside the menu icon, the menu list is gone", menuList.isDisplayed());
}

From source file:com.ibm.watson.app.qaclassifier.selenium.MenuIT.java

License:Open Source License

@Test
public void closeMenuOverlayByClickingOutsideOfContent() {
    WebElement menuIconContainer = driver.findElement(By.id("menuIconContainerDesktop"));
    WebElement menuIconImg = menuIconContainer
            .findElement(By.xpath(".//span[contains(concat(' ', @class, ' '), ' menuIconImg ')]"));

    menuIconImg.click();/*from   w  w  w  .ja  v a  2  s  .  c  o  m*/
    WebElement menuList = driver.findElement(By.className("menu-list"));
    List<WebElement> menuOptions = menuList.findElements(By.xpath(".//ul/li"));

    // The first item should be home, which is hidden on Desktop, so skip it and do the second one
    WebElement firstMenuOption = menuOptions.get(2);
    firstMenuOption.click();

    // Click outside of the content
    WebElement menuOverlay = driver.findElement(By.id("menuOverlay"));
    WebElement menuContent = menuOverlay.findElement(By.xpath(".//div[@id='menu']"));
    Actions action = new Actions(driver);
    action.moveToElement(menuContent, -1, -1);
    action.click().build().perform();
    assertTrue("Clicking outside of the content closes the menu overlay",
            driver.findElements(By.id("menuOverlay")).size() == 0);
}