Example usage for org.openqa.selenium Point getY

List of usage examples for org.openqa.selenium Point getY

Introduction

In this page you can find the example usage for org.openqa.selenium Point getY.

Prototype

public int getY() 

Source Link

Usage

From source file:org.mousephenotype.cda.selenium.support.TestUtils.java

License:Apache License

/**
 * Scrolls <code>element</code> to the top
 * @param driver <code>WebDriver</code> instance
 * @param element Element to scroll to top
 * @param yOffsetInPixels An <code>Integer</code> which, if not null and not 0,
 *     first scrolls the element to the top, then further scrolls it <code>
 *     yOffsetInPixels</code> pixels down (if negative number) or up (if
 *     positive).//from   w ww  .j av a2  s. c o m
 */
public void scrollToTop(WebDriver driver, WebElement element, Integer yOffsetInPixels) {
    Point p = element.getLocation();
    ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);

    if ((yOffsetInPixels != null) && (yOffsetInPixels != 0)) {
        ((JavascriptExecutor) driver)
                .executeScript("window.scroll(" + p.getX() + "," + (p.getY() + yOffsetInPixels) + ");");
    }

    commonUtils.sleep(100);
}

From source file:org.mousephenotype.www.testing.model.TestUtils.java

License:Apache License

/**
 * Scrolls <code>element</code> to the top
 * @param driver <code>WebDriver</code> instance
 * @param element Element to scroll to top
 * @param yOffsetInPixels An <code>Integer</code> which, if not null and not 0,
 *     first scrolls the element to the top, then further scrolls it <code>
 *     yOffsetInPixels</code> pixels down (if negative number) or up (if
 *     positive)./*from  w ww .j  av  a2s.com*/
 */
public static void scrollToTop(WebDriver driver, WebElement element, Integer yOffsetInPixels) {
    Point p = element.getLocation();
    ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);

    if ((yOffsetInPixels != null) && (yOffsetInPixels != 0)) {
        ((JavascriptExecutor) driver)
                .executeScript("window.scroll(" + p.getX() + "," + (p.getY() + yOffsetInPixels) + ");");
    }

    sleep(100);
}

From source file:org.oneandone.qxwebdriver.ui.core.scroll.AbstractScrollArea.java

License:LGPL

public Boolean isChildInView(WebElement child) {
    Point paneLocation = contentElement.getLocation();
    int paneTop = paneLocation.getY();
    int paneLeft = paneLocation.getX();
    Dimension paneSize = contentElement.getSize();
    int paneHeight = paneSize.height;
    int paneBottom = paneTop + paneHeight;
    int paneWidth = paneSize.width;
    int paneRight = paneLeft + paneWidth;

    Point childLocation = child.getLocation();
    int childTop = childLocation.getY();
    int childLeft = childLocation.getX();

    if (childTop >= paneTop && childTop < paneBottom && childLeft >= paneLeft && childLeft < paneRight) {
        return true;
    }//w w  w . j  av a  2s . c o m

    return false;
}

From source file:org.oneandone.qxwebdriver.ui.mobile.core.WidgetImpl.java

License:LGPL

public static void longtap(WebDriver driver, WebElement element) {
    if (driver instanceof HasTouchScreen) {
        TouchActions longtap = new TouchActions(driver);
        Point center = getCenter(element);
        longtap.down(center.getX(), center.getY());
        longtap.perform();/*  w w  w .j  a  v  a  2s  .c  om*/
        try {
            Thread.sleep(750);
        } catch (InterruptedException e) {
        }
        longtap.up(center.getX(), center.getY());
        longtap.perform();
    } else {
        Locatable locatable = (Locatable) element;
        Coordinates coords = locatable.getCoordinates();
        Mouse mouse = ((HasInputDevices) driver).getMouse();
        mouse.mouseDown(coords);
        try {
            Thread.sleep(750);
        } catch (InterruptedException e) {
        }
        mouse.mouseUp(coords);
    }
}

From source file:org.oneandone.qxwebdriver.ui.mobile.core.WidgetImpl.java

License:LGPL

protected static Point getCenter(WebElement element) {
    Dimension size = element.getSize();
    int halfWidth = size.getWidth() / 2;
    int halfHeight = size.getHeight() / 2;

    Point loc = element.getLocation();
    int posX = loc.getX() + halfWidth;
    int posY = loc.getY() + halfHeight;

    Point point = new Point(posX, posY);
    return point;
}

From source file:org.oneandone.qxwebdriver.ui.mobile.core.WidgetImpl.java

License:LGPL

public static void track(WebDriver driver, WebElement element, int x, int y, int step) {
    if (driver instanceof HasTouchScreen) {
        if (step == 0) {
            step = 1;/* w  w  w .  j  av a2 s  . co m*/
            // TODO: no move if step == 0
        }

        Point center = getCenter(element);

        int posX = center.getX();
        int posY = center.getY();

        int endX = posX + x;
        int endY = posY + y;

        TouchActions touchAction = new TouchActions(driver);
        touchAction.down(posX, posY);

        while ((x < 0 && posX > endX || x > 0 && posX < endX)
                || (y < 0 && posY > endY || y > 0 && posY < endY)) {
            if (x > 0 && posX < endX) {
                if (posX + step > endX) {
                    posX += endX - (posX + step);
                } else {
                    posX += step;
                }
            }

            else if (x < 0 && posX > endX) {
                if (posX - step < endX) {
                    posX -= endX + (posX - step);
                } else {
                    posX -= step;
                }
            }

            if (y > 0 && posY < endY) {
                if (posY + step > endY) {
                    posY += endY - (posY + step);
                } else {
                    posY += step;
                }
            }

            else if (y < 0 && posY > endY) {
                if (posY - step < endY) {
                    posY -= endY + (posY - step);
                } else {
                    posY -= step;
                }
            }

            touchAction.move(posX, posY);
        }

        touchAction.up(posX, posY).perform();
    } else {
        Actions mouseAction = new Actions(driver);
        mouseAction.dragAndDropBy(element, x, y);
    }
}

From source file:org.richfaces.bootstrap.demo.ftest.webdriver.pickList.fragment.PickListSelectionImpl.java

License:Open Source License

/**
 * Workaround for Drag and Drop//from  ww  w  .  jav a  2  s.co  m
 */
private void dragAndDropAction(WithOffset offset, Actions builder, WebElement source, WebElement target) {
    Point sourceLocation = source.getLocation();
    Point targetLocation = target.getLocation();
    int x = targetLocation.getX() - sourceLocation.getX() + offset.getOffset();
    int y = targetLocation.getY() - sourceLocation.getY() + offset.getOffset();
    builder.dragAndDropBy(source, x, y);
    //            builder.clickAndHold(source);
    //            builder.moveToElement(target);
    //            builder.moveByOffset(offset.getOffset(),offset.getOffset());//second move will throw exception
    //            builder.release();
}

From source file:org.richfaces.showcase.contextMenu.AbstractContextMenuTest.java

License:Open Source License

private double getDistance(Point point1, Point point2) {
    java.awt.Point point3 = new java.awt.Point(point1.getX(), point1.getY());
    java.awt.Point point4 = new java.awt.Point(point2.getX(), point2.getY());

    return point3.distance(point4);
}

From source file:org.richfaces.tests.metamer.ftest.richContextMenu.TestRichContextMenuWebDriver.java

License:Open Source License

@Test
public void testVerticalOffset() {
    int offset = 11;
    // show context menu
    page.clickOnFirstPanel(driverType);//ww  w  .  ja  v a 2 s.c  om
    // check whether the context menu is displayed
    page.checkIfContextMenuDisplayed(driver);
    // get position before offset is set
    Point before = page.contextMenuContent.getLocation();
    // set verticalOffset
    contextMenuAttributes.set(ContextMenuAttributes.verticalOffset, offset);
    // show context menu
    page.clickOnFirstPanel(driverType);
    // check whether the context menu is displayed
    page.checkIfContextMenuDisplayed(driver);
    // get position after offset is set
    Point after = page.contextMenuContent.getLocation();
    // check offset
    assertEquals(before.getY(), after.getY() - offset);
}

From source file:org.richfaces.tests.showcase.ftest.webdriver.page.AbstractTreePage.java

License:Open Source License

private void toggle(WebElement toToggle) {
    if (webDriver instanceof JavascriptExecutor) {
        Point location = toToggle.getLocation();
        JavascriptExecutor jsExecutor = (JavascriptExecutor) webDriver;
        jsExecutor.executeScript("window.moveTo(" + location.getX() + ", " + location.getY() + ")");
    }//from  ww  w .j a  va2  s .  co m
    toToggle.click();
    Graphene.waitAjax().withMessage("Unable to toggle the given element.")
            .until(Graphene.element(toToggle).isPresent());
}