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

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

Introduction

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

Prototype

public Actions(WebDriver driver) 

Source Link

Usage

From source file:com.seleniumtests.uipage.htmlelements.HtmlElement.java

License:Apache License

/**
 * Double Click with CompositeActions//w w w .ja va 2 s. c om
 */
@ReplayOnError
public void doubleClickAction() {
    findElement(true);

    try {
        new Actions(driver).doubleClick(element).perform();
    } catch (InvalidElementStateException e) {
        logger.error(e);
    }
}

From source file:com.seleniumtests.uipage.htmlelements.HtmlElement.java

License:Apache License

/**
 * Click element in native way by Actions.
 *
 * <p/>/*from   w  ww  .j  a  v  a 2s  .  c o m*/
 * <pre class="code">
   clickAt(1, 1);
 * </pre>
 *
 * @param  value
 */
@ReplayOnError
public void clickAt(int xOffset, int yOffset) {
    findElement();
    ((CustomEventFiringWebDriver) driver).scrollToElement(element, yOffset);

    try {
        new Actions(driver).moveToElement(element, xOffset, yOffset).click().perform();
    } catch (InvalidElementStateException e) {
        logger.error(e);
        element.click();
    }
}

From source file:com.seleniumtests.uipage.htmlelements.HtmlElement.java

License:Apache License

/**
 * Send keys through composite actions/*  www  .j  ava 2  s  . c  o  m*/
 * /!\ does not clear text before and no blur after
 * 
 * @param keysToSend
 */
@ReplayOnError
public void sendKeysAction(CharSequence... keysToSend) {
    findElement(true);
    new Actions(driver).sendKeys(element, keysToSend).build().perform();
}

From source file:com.seleniumtests.uipage.htmlelements.PictureElement.java

License:Apache License

/**
 * Move to the center of the picture//from w w w .  ja v a  2  s.  c o m
 * @param element   The element to move to
 * @param coordX   x offset from the center of the element
 * @param coordY   y offset from the center of the element
 * @return
 */
private Actions move(WebElement element, int coordX, int coordY) {

    if (SeleniumTestsContextManager.isWebTest()) {
        // issue #133: handle new actions specific case
        // more browsers will be added to this conditions once they are migrated to new composite actions
        if (SeleniumTestsContextManager.getThreadContext().getBrowser() == BrowserType.FIREFOX) {
            // issue #133: firefox moves to center of element in page
            coordX -= element.getSize().width / 2;
            coordY -= element.getSize().height / 2;
        } else if (SeleniumTestsContextManager.getThreadContext()
                .getBrowser() == BrowserType.INTERNET_EXPLORER) {
            // issue #180: internet explorer moves to center of element in viewport
            Dimension viewportDim = ((CustomEventFiringWebDriver) (WebUIDriver.getWebDriver()))
                    .getViewPortDimensionWithoutScrollbar();
            coordX -= Math.min(element.getSize().width, viewportDim.width) / 2;
            coordY -= Math.min(element.getSize().height, viewportDim.height) / 2;
        }
    }

    return new Actions(WebUIDriver.getWebDriver()).moveToElement(element, coordX, coordY);
}

From source file:com.seleniumtests.uipage.htmlelements.PictureElement.java

License:Apache License

public void sendKeys(final CharSequence text, int xOffset, int yOffset) {
    clickAt(xOffset, yOffset);//from  ww  w  . j  a  v a  2s .  c  om

    new Actions(WebUIDriver.getWebDriver()).sendKeys(text).build().perform();
}

From source file:com.seleniumtests.uipage.PageObject.java

License:Apache License

/**
 * Drags an element a certain distance and then drops it.
 *
 * @param  element  to dragAndDrop//  w  w w .ja  va2s.c  om
 * @param  offsetX  in pixels from the current location to which the element should be moved, e.g., 70
 * @param  offsetY  in pixels from the current location to which the element should be moved, e.g., -300
 */
public void dragAndDrop(final HtmlElement element, final int offsetX, final int offsetY) {
    new Actions(driver).dragAndDropBy((WebElement) element.getElement(), offsetX, offsetY).perform();
}

From source file:com.seleniumtests.ut.uipage.htmlelements.TestCompositeActions.java

License:Apache License

/**
 * Checks that CompositeAction.updateHandles() aspect is called when 
 * a click is done in a composite action
 * @throws Exception//from   w w  w .  ja  v  a  2  s  .  c om
 */
@Test(groups = { "ut" })
public void testUpdateHandles() throws Exception {
    new Actions(eventDriver).click().perform();

    // check handled are updated on click
    verify(eventDriver).updateWindowsHandles();
}

From source file:com.seleniumtests.ut.uipage.htmlelements.TestCompositeActions.java

License:Apache License

@Test(groups = { "ut" })
public void testHandlesNotUpdated() throws Exception {
    new Actions(eventDriver).clickAndHold().perform();

    // check handled are not updated when no click is done
    verify(eventDriver, never()).updateWindowsHandles();
}

From source file:com.seleniumtests.ut.uipage.htmlelements.TestCompositeActions.java

License:Apache License

/**
 * Checks that CompositeAction.updateHandles() aspect is called when 
 * a click is done in a composite action with a driver supporting new actions (the real driver)
 * @throws Exception//from   w  w  w .  j a v  a  2s.  c om
 */
@Test(groups = { "ut" })
public void testUpdateHandlesNewActions() throws Exception {
    new Actions(eventDriver.getWebDriver()).click().perform();

    // check handles are updated on click
    verify(eventDriver).updateWindowsHandles();
}

From source file:com.seleniumtests.ut.uipage.htmlelements.TestCompositeActions.java

License:Apache License

/**
 * No update when only down or up action is done
 * @throws Exception/* w w w.j  av  a2s  .  c  o  m*/
 */
@Test(groups = { "ut" })
public void testUpdateHandlesNotUpdatedNewActions() throws Exception {
    new Actions(eventDriver.getWebDriver()).clickAndHold().perform();

    // check handled are updated on click
    verify(eventDriver, never()).updateWindowsHandles();
}