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:com.google.android.testing.nativedriver.server.AndroidNativeTouch.java

License:Apache License

@Override
public synchronized void longClick(Coordinates where) {
    if (!isTouchStateReleased()) {
        throw new IllegalStateException("Attempt to longclick when touch state is already down");
    }//from w ww .ja va2s. c om
    updateActiveCoordinates(where);
    Point point = currentActiveCoordinates.getLocationOnScreen();
    longClick(point.getX(), point.getY());
}

From source file:com.googlecode.fightinglayoutbugs.DetectElementsWithInvisibleFocus.java

License:Apache License

private FocusedElement toFocusedElement(@Nonnull WebElement activeElement, WebPage webPage) {
    // I don't trust WebDriver, that's why I determine the offset, width and height with jQuery too ...
    Map temp = new Gson()
            .fromJson(//from  ww  w .j a  va2 s.  com
                    (String) webPage.executeJavaScript(
                            "var $element = jQuery(arguments[0]);\n" + "var offset = $element.offset();\n"
                                    + "var $temp = $element.clone(false).wrap('<div></div>').parent();\n"
                                    + "try {\n" + "    return JSON.stringify({\n" + "        x: offset.left,\n"
                                    + "        y: offset.top,\n" + "        w: $element.width(),\n"
                                    + "        h: $element.height(),\n" + "        html: $temp.html()\n"
                                    + "    });\n" + "} finally {\n" + "    $temp.remove();\n" + "}",
                            activeElement),
                    Map.class);
    int x = ((Number) temp.get("x")).intValue();
    int y = ((Number) temp.get("y")).intValue();
    int w = ((Number) temp.get("w")).intValue();
    int h = ((Number) temp.get("h")).intValue();
    String html = (String) temp.get("html");
    if (activeElement.isDisplayed()) {
        Point location = activeElement.getLocation();
        Dimension size = activeElement.getSize();
        int x1 = Math.min(location.getX(), x);
        int y1 = Math.min(location.getY(), y);
        int x2 = Math.max(location.getX() + size.getWidth(), x + w) - 1;
        int y2 = Math.max(location.getY() + size.getHeight(), y + h) - 1;
        return new FocusedElement(activeElement, new RectangularRegion(x1, y1, x2, y2), html);
    } else {
        return new FocusedElement(activeElement, NOT_DISPLAYED, html);
    }
}

From source file:com.induscorp.prime.testing.ui.core.objects.DOMObjectValidator.java

License:Open Source License

@Override
public void rightClick(int numRetries) {
    try {//from ww w .j  ava2s .c  o m
        WebElement webElem = findElement(numRetries);
        Point location = webElem.getLocation();
        Dimension size = webElem.getSize();

        browser.getSikuliScreen()
                .rightClick(new Region(location.getX(), location.getY(), size.getWidth(), size.getHeight()));
    } catch (Throwable th) {
        Assert.fail("Failed to perform mouse right click on element '" + domObject.getDisplayName() + "'.", th);
    }
}

From source file:com.induscorp.prime.testing.ui.core.objects.scrollbar.Scrollbar.java

License:Open Source License

/**
 * Scroll element into//from w  ww  .  ja  v a2  s .c  o  m
 * 
 * @param elemLocator
 * @param searchDirection
 *            direction to locate element from the current focus point.
 */
public void scrollElementToViewport(WebBrowser browser, UIObject elemLocator) {
    if (elemLocator.getLocatorType() == LocatorType.DOM) {
        UIObject domLocator = elemLocator;
        WebElement webElem = null;
        try {
            // Rectangle hScrollbarThumbGripCurrLocation  =
            // findHScrollbarThumbGripLeftPartImageLocation();
            System.out.println("AAA");
            Rectangle vScrollbarThumbGripCurrLocation = findVScrollbarThumbGripTopPartImageLocation();

            webElem = (WebElement) domLocator.getValidator(browser, null).findElementNoException(0);
            boolean hsbEndReached, vsbEndReached = false;
            boolean vsbTGCurrPointReached = false;
            int vsbEndReachedCounter = 0;
            do { // Move vertical scrollbar
                hsbEndReached = false;
                do { // Move horizontal scrollbar
                    if (webElem != null) {
                        if (hScrollbar != null) {
                            Point webElemPoint = webElem.getLocation();
                            Match hscM1 = hScrollbar.findLeftScrollImage(hScrollbarRegion);
                            if (webElemPoint.getX() - hscM1.getX() <= 80) {
                                break;
                            } else if (hsbEndReached) {
                                break;
                            } else {
                                hsbEndReached = hScrollbar.clickRightScrollImage(hScrollbarRegion, 2);
                                webElem = (WebElement) domLocator.getValidator(browser, null)
                                        .findElementNoException(0);
                                if (webElem == null) {
                                    hScrollbar.clickLeftScrollImage(hScrollbarRegion, 2);
                                    webElem = (WebElement) domLocator.getValidator(browser, null)
                                            .findElementNoException(0);
                                    break;
                                }
                            }
                        } else {
                            break;
                        }
                    } else {
                        if (hScrollbar != null) {
                            if (hsbEndReached) {
                                hScrollbar.scrollThumbGripToExtremeLeft(hScrollbarRegion);
                                break;
                            } else {
                                hsbEndReached = hScrollbar.clickRightScrollImage(hScrollbarRegion, 2);
                                webElem = (WebElement) domLocator.getValidator(browser, null)
                                        .findElementNoException(0);
                                continue;
                            }
                        } else {
                            break;
                        }
                    }
                } while (true); // -----done ----

                if (webElem != null) {
                    if (vScrollbar != null) {
                        Point webElemPoint = webElem.getLocation();
                        Match vscM1 = vScrollbar.findTopScrollImage(vScrollbarRegion);
                        if (webElemPoint.getY() - vscM1.getY() <= 80) {
                            break;
                        } else if (vsbEndReached) {
                            break;
                        } else {
                            vsbEndReached = vScrollbar.clickBottomScrollImage(vScrollbarRegion, 2);
                            webElem = (WebElement) domLocator.getValidator(browser, null)
                                    .findElementNoException(0);
                            if (webElem == null) {
                                vScrollbar.clickTopScrollImage(vScrollbarRegion, 2);
                                webElem = (WebElement) domLocator.getValidator(browser, null)
                                        .findElementNoException(0);
                                break;
                            }
                        }
                    } else {
                        break;
                    }
                } else {
                    if (vScrollbar != null) {
                        if (vsbEndReachedCounter > 0 && vsbTGCurrPointReached) {
                            break;
                        } else if (vsbEndReachedCounter == 0 && vsbEndReached) {
                            vScrollbar.scrollThumbGripToExtremeTop(vScrollbarRegion);
                            vsbEndReached = false;
                            vsbEndReachedCounter++;
                            continue;
                        } else {
                            vsbEndReached = vScrollbar.clickBottomScrollImage(vScrollbarRegion, 2);
                            Rectangle vScrollbarThumbGripRunLocation = findVScrollbarThumbGripTopPartImageLocation();
                            if (vScrollbarThumbGripRunLocation.getY()
                                    - vScrollbarThumbGripCurrLocation.getY() >= 0) {
                                vsbTGCurrPointReached = true;
                            }
                            webElem = (WebElement) domLocator.getValidator(browser, null)
                                    .findElementNoException(0);
                            continue;
                        }
                    } else {
                        break;
                    }
                }
            } while (true);

        } catch (Throwable th) {
            Assert.fail("Failed to scroll element '" + elemLocator.getDisplayName() + "' into view port.", th);
        }
        Assert.assertNotNull(webElem, "Failed to find element '" + elemLocator.getDisplayName() + "'");

    } else if (elemLocator.getLocatorType() == LocatorType.IMAGE) {
        UIObject imgLocator = elemLocator;
        Match match = null;
        try {
            // Rectangle hScrollbarThumbGripCurrLocation =
            // findHScrollbarThumbGripLeftPartImageLocation();
            Rectangle vScrollbarThumbGripCurrLocation = findVScrollbarThumbGripTopPartImageLocation();

            match = (Match) imgLocator.getValidator(browser, null).findElementNoException(0);
            boolean hsbEndReached, vsbEndReached = false;
            boolean vsbTGCurrPointReached = false;
            int vsbEndReachedCounter = 0;
            do { // Move vertical scrollbar
                hsbEndReached = false;
                do { // Move horizontal scrollbar
                    if (match != null) {
                        if (hScrollbar != null) {
                            // Point webElemPoint = match.getLocation();
                            Match hscM1 = hScrollbar.findLeftScrollImage(hScrollbarRegion);
                            if (match.getX() - hscM1.getX() <= 80) {
                                break;
                            } else if (hsbEndReached) {
                                break;
                            } else {
                                hsbEndReached = hScrollbar.clickRightScrollImage(hScrollbarRegion, 2);
                                match = (Match) imgLocator.getValidator(browser, null)
                                        .findElementNoException(0);
                                if (match == null) {
                                    hScrollbar.clickLeftScrollImage(hScrollbarRegion, 2);
                                    match = (Match) imgLocator.getValidator(browser, null)
                                            .findElementNoException(0);
                                    break;
                                }
                            }
                        } else {
                            break;
                        }
                    } else {
                        if (hScrollbar != null) {
                            if (hsbEndReached) {
                                hScrollbar.scrollThumbGripToExtremeLeft(hScrollbarRegion);
                                break;
                            } else {
                                hsbEndReached = hScrollbar.clickRightScrollImage(hScrollbarRegion, 2);
                                match = (Match) imgLocator.getValidator(browser, null)
                                        .findElementNoException(0);
                                continue;
                            }
                        } else {
                            break;
                        }
                    }
                } while (true); // -----done ----

                if (match != null) {
                    if (vScrollbar != null) {
                        // Point webElemPoint = match.getLocation();
                        Match vscM1 = vScrollbar.findTopScrollImage(vScrollbarRegion);
                        if (match.getY() - vscM1.getY() <= 80) {
                            break;
                        } else if (vsbEndReached) {
                            break;
                        } else {
                            vsbEndReached = vScrollbar.clickBottomScrollImage(vScrollbarRegion, 2);
                            match = (Match) imgLocator.getValidator(browser, null).findElementNoException(0);
                            if (match == null) {
                                vScrollbar.clickTopScrollImage(vScrollbarRegion, 2);
                                match = (Match) imgLocator.getValidator(browser, null)
                                        .findElementNoException(0);
                                break;
                            }
                        }
                    } else {
                        break;
                    }
                } else {
                    if (vScrollbar != null) {
                        if (vsbEndReachedCounter > 0 && vsbTGCurrPointReached) {
                            break;
                        } else if (vsbEndReachedCounter == 0 && vsbEndReached) {
                            vScrollbar.scrollThumbGripToExtremeTop(vScrollbarRegion);
                            vsbEndReached = false;
                            vsbEndReachedCounter++;
                            continue;
                        } else {
                            vsbEndReached = vScrollbar.clickBottomScrollImage(vScrollbarRegion, 2);
                            Rectangle vScrollbarThumbGripRunLocation = findVScrollbarThumbGripTopPartImageLocation();
                            if (vScrollbarThumbGripRunLocation.getY()
                                    - vScrollbarThumbGripCurrLocation.getY() >= 0) {
                                vsbTGCurrPointReached = true;
                            }
                            match = (Match) imgLocator.getValidator(browser, null).findElementNoException(0);
                            continue;
                        }
                    } else {
                        break;
                    }
                }
            } while (true);

        } catch (Throwable th) {
            Assert.fail("Failed to scroll element '" + elemLocator.getDisplayName() + "' into view port.", th);
        }
        Assert.assertNotNull(match, "Failed to find element '" + elemLocator.getDisplayName() + "'");
    }

}

From source file:com.liferay.cucumber.selenium.BaseWebDriverImpl.java

License:Open Source License

public void clickAt(String locator, String coordString, boolean scrollIntoView) {

    int offsetX = 0;
    int offsetY = 0;

    if (Validator.isNotNull(coordString) && coordString.contains(",")) {
        String[] coords = coordString.split(",");

        offsetX = GetterUtil.getInteger(coords[0]);
        offsetY = GetterUtil.getInteger(coords[1]);
    }//ww  w.j av a 2  s.co m

    if ((offsetX == 0) && (offsetY == 0)) {
        click(locator);
    } else {
        WebElement bodyWebElement = getWebElement("//body");

        WrapsDriver wrapsDriver = (WrapsDriver) bodyWebElement;

        WebDriver webDriver = wrapsDriver.getWrappedDriver();

        WebDriver.Options options = webDriver.manage();

        WebDriver.Window window = options.window();

        Point windowPoint = window.getPosition();

        WebElement webElement = getWebElement(locator);

        Point webElementPoint = webElement.getLocation();

        int clickDestinationX = 0;
        int clickDestinationY = 0;

        if (scrollIntoView) {
            scrollWebElementIntoView(webElement);

            clickDestinationX = windowPoint.getX() + webElementPoint.getX() + offsetX;
            clickDestinationY = windowPoint.getY() + offsetY;
        } else {
            clickDestinationX = windowPoint.getX() + webElementPoint.getX() + offsetX;
            clickDestinationY = windowPoint.getY() + webElementPoint.getY() + offsetY;
        }

        try {
            Robot robot = new Robot();

            robot.mouseMove(clickDestinationX, clickDestinationY);

            robot.mousePress(KeyEvent.BUTTON1_MASK);

            robot.delay(1500);

            robot.mouseRelease(KeyEvent.BUTTON1_MASK);

            robot.delay(1500);
        } catch (Exception e) {
        }
    }
}

From source file:com.liferay.cucumber.selenium.WebDriverHelper.java

License:Open Source License

public static int getElementPositionTop(WebDriver webDriver, String locator) {

    WebElement webElement = getWebElement(webDriver, locator, "1");

    Point point = webElement.getLocation();

    return point.getY();
}

From source file:com.liferay.cucumber.selenium.WebDriverHelper.java

License:Open Source License

public static Point getFramePoint(WebDriver webDriver) {
    int x = 0;/*from   w  w  w  .  java2s.c  o  m*/
    int y = 0;

    WebElement bodyWebElement = getWebElement(webDriver, "//body");

    WrapsDriver wrapsDriver = (WrapsDriver) bodyWebElement;

    WebDriver wrappedWebDriver = wrapsDriver.getWrappedDriver();

    WebDriver.TargetLocator targetLocator = wrappedWebDriver.switchTo();

    targetLocator.window(_defaultWindowHandle);

    for (WebElement webElement : _frameWebElements) {
        Point point = webElement.getLocation();

        x += point.getX();
        y += point.getY();

        targetLocator.frame(webElement);
    }

    return new Point(x, y);
}

From source file:com.liferay.cucumber.selenium.WebDriverHelper.java

License:Open Source License

public static int getFramePositionTop(WebDriver webDriver) {
    Point point = getFramePoint(webDriver);

    return point.getY();
}

From source file:com.liferay.cucumber.selenium.WebDriverHelper.java

License:Open Source License

public static int getWindowPositionTop(WebDriver webDriver) {
    Point point = getWindowPoint(webDriver);

    return point.getY();
}

From source file:com.lohika.alp.flexpilot.driver.FlexPilotElement.java

License:Open Source License

public void dragAndDrop(Point point) {
    execute(DriverCommand.DRAG_DROP_TO_COORDS,
            ImmutableMap.of("id", id, "offsetx", point.getX(), "offsety", point.getY()));
}