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.uiautomation.ios.server.command.uiautomation.FlickNHandler.java

License:Apache License

public FlickNHandler(IOSServerManager driver, WebDriverLikeRequest request) throws Exception {
    super(driver, request);

    JSONObject payload = request.getPayload();
    String elementId = payload.optString("element");

    Point fromPoint;
    Dimension screenSize = driver.getSession(request.getSession()).getNativeDriver().getScreenSize();

    if (!payload.isNull("element") && !elementId.equals("")) {
        try {/* w w w.  jav  a2 s . co  m*/
            RemoteWebNativeBackedElement element = (RemoteWebNativeBackedElement) getSession()
                    .getRemoteWebDriver().createElement(elementId);
            fromPoint = element.getLocation();
        } catch (Exception e) {
            fromPoint = getStartCoordinatesCentered(request, elementId);
        }
    } else {
        fromPoint = new Point(screenSize.getWidth() / 2, screenSize.getHeight() / 2);
    }

    String xOffset = payload.optString("xoffset");
    if (xOffset.equals("")) {
        xOffset = payload.optString("xspeed");
    }
    String yOffset = payload.optString("yoffset");
    if (yOffset.equals("")) {
        yOffset = payload.optString("yspeed");
    }

    String speed = payload.optString("speed").equals("") ? "1" : payload.optString("speed");
    if (Integer.valueOf(speed) < .5) {
        speed = "0.5";
    }

    Point toPoint = new Point(fromPoint.getX() + Integer.valueOf(xOffset),
            fromPoint.getY() + Integer.valueOf(yOffset));

    fromPoint = CoordinateUtils.forcePointOnScreen(fromPoint, screenSize);
    toPoint = CoordinateUtils.forcePointOnScreen(toPoint, screenSize);

    String js = dragTemplate.replace(":sessionId", request.getSession())
            .replace("fromX", String.valueOf(fromPoint.getX()))
            .replace("fromY", String.valueOf(fromPoint.getY())).replace("toX", String.valueOf(toPoint.getX()))
            .replace("toY", String.valueOf(toPoint.getY())).replace("duration", speed);
    setJS(js);
}

From source file:org.uiautomation.ios.server.command.web.DoubleTapHandler.java

License:Apache License

public DoubleTapHandler(IOSServerManager driver, WebDriverLikeRequest request) throws Exception {
    super(driver, request);

    JSONObject payload = request.getPayload();
    String elementId = payload.optString("element");

    Dimension screenSize = driver.getSession(request.getSession()).getNativeDriver().getScreenSize();
    RemoteWebNativeBackedElement element = (RemoteWebNativeBackedElement) getSession().getRemoteWebDriver()
            .createElement(elementId);// www .j  ava  2s  .c  o  m
    Point tapPoint = element.getLocation();
    tapPoint = CoordinateUtils.forcePointOnScreen(tapPoint, screenSize);

    String js = doubleTapTemplate.replace(":sessionId", request.getSession())
            .replace("tapX", Integer.toString(tapPoint.getX()))
            .replace("tapY", Integer.toString(tapPoint.getY()));

    setJS(js);
}

From source file:org.uiautomation.ios.server.command.web.LongTapHandler.java

License:Apache License

public LongTapHandler(IOSServerManager driver, WebDriverLikeRequest request) throws Exception {
    super(driver, request);

    JSONObject payload = request.getPayload();
    String elementId = payload.optString("element");

    Dimension screenSize = driver.getSession(request.getSession()).getNativeDriver().getScreenSize();
    RemoteWebNativeBackedElement element = (RemoteWebNativeBackedElement) getSession().getRemoteWebDriver()
            .createElement(elementId);/*from  w  w  w  .  j a  v a2  s  .  c  o m*/
    Point tapPoint = element.getLocation();
    tapPoint = CoordinateUtils.forcePointOnScreen(tapPoint, screenSize);

    String js = longTapTemplate.replace(":sessionId", request.getSession())
            .replace("tapX", Integer.toString(tapPoint.getX()))
            .replace("tapY", Integer.toString(tapPoint.getY()));

    setJS(js);
}

From source file:org.uiautomation.ios.server.command.web.ScrollHandler.java

License:Apache License

public ScrollHandler(IOSServerManager driver, WebDriverLikeRequest request) throws Exception {
    super(driver, request);

    JSONObject payload = request.getPayload();
    String elementId = payload.optString("element");

    Dimension screenSize = driver.getSession(request.getSession()).getNativeDriver().getScreenSize();

    Point fromPoint;
    if (!payload.isNull("element") && !elementId.equals("")) {
        RemoteWebNativeBackedElement element = (RemoteWebNativeBackedElement) getSession().getRemoteWebDriver()
                .createElement(elementId);
        fromPoint = element.getLocation();
    } else {/*from  w w w .ja va  2  s .  c o m*/
        fromPoint = new Point(screenSize.getWidth() / 2, screenSize.getHeight() / 2);
    }
    fromPoint = CoordinateUtils.forcePointOnScreen(fromPoint, screenSize);
    Point toPoint = new Point(fromPoint.getX() + payload.getInt("xoffset"),
            fromPoint.getY() + payload.getInt("yoffset"));
    toPoint = CoordinateUtils.forcePointOnScreen(toPoint, screenSize);
    String js = scrollTemplate.replace(":sessionId", request.getSession())
            .replace("fromX", Integer.toString(fromPoint.getX()))
            .replace("fromY", Integer.toString(fromPoint.getY()))
            .replace("toX", Integer.toString(toPoint.getX())).replace("toY", Integer.toString(toPoint.getY()));

    setJS(js);
}

From source file:org.uiautomation.ios.server.command.web.TapHandler.java

License:Apache License

public TapHandler(IOSServerManager driver, WebDriverLikeRequest request) throws Exception {
    super(driver, request);

    JSONObject payload = request.getPayload();
    String elementId = payload.optString("element");

    //String ref = request.getVariableValue(":reference");
    Dimension screenSize = driver.getSession(request.getSession()).getNativeDriver().getScreenSize();
    RemoteWebNativeBackedElement element = (RemoteWebNativeBackedElement) getSession().getRemoteWebDriver()
            .createElement(elementId);/*from   w  w  w.  j a  va  2 s.c o  m*/
    Point tapPoint = element.getLocation();
    tapPoint = CoordinateUtils.forcePointOnScreen(tapPoint, screenSize);

    String js = tapTemplate.replace(":sessionId", request.getSession())
            .replace("tapX", Integer.toString(tapPoint.getX()))
            .replace("tapY", Integer.toString(tapPoint.getY()));

    setJS(js);
}

From source file:org.uiautomation.ios.server.utils.CoordinateUtils.java

License:Apache License

public static Point forcePointOnScreen(Point point, Dimension screenSize) {

    int x;//from  w w  w  .  j a  v a 2s. c  o m
    int y;

    if (point.getX() < 0) {
        x = 0;
    } else if (point.getX() > screenSize.getWidth()) {
        x = screenSize.getWidth();
    } else {
        x = point.getX();
    }

    if (point.getY() < 0) {
        y = 0;
    } else if (point.getY() > screenSize.getHeight()) {
        y = screenSize.getHeight();
    } else {
        y = point.getY();
    }

    return new Point(x, y);

}

From source file:org.uiautomation.ios.server.utils.CoordinateUtils.java

License:Apache License

public static Point getCenterPoint(Point topLeft, Dimension size) {
    return getCenterPoint(topLeft.getX(), topLeft.getY(), size.getWidth(), size.getHeight());

}

From source file:org.uiautomation.ios.server.utils.CoordinateUtils.java

License:Apache License

public static Point getCenterPointFromElement(RemoteWebElement element) throws Exception {
    Point location = element.getLocation();
    Dimension size = element.getSize();
    return getCenterPoint(location.getX(), location.getY(), size.getWidth(), size.getHeight());
}

From source file:org.uiautomation.ios.webInspector.DOM.RemoteWebNativeBackedElement.java

License:Apache License

private String getNativeElementClickOnIt() throws Exception {
    // web stuff.
    scrollIntoViewIfNeeded();/*w  w w. j  a v a2s  . c om*/
    Point po = findPosition();

    Dimension dim = inspector.getSize();
    int webPageWidth = inspector.getInnerWidth();
    if (dim.getWidth() != webPageWidth) {
        log.fine("BUG : dim.getWidth()!=webPageWidth");
    }

    Criteria c = new TypeCriteria(UIAWebView.class);
    String json = c.stringify().toString();
    StringBuilder script = new StringBuilder();
    script.append("var root = UIAutomation.cache.get('1');");
    script.append("var webview = root.element(-1," + json + ");");
    script.append("var webviewSize = webview.rect();");
    script.append("var ratio = webviewSize.size.width / " + dim.getWidth() + ";");
    int top = po.getY();
    int left = po.getX();
    script.append("var top = (" + top + "*ratio )+1;");
    script.append("var left = (" + left + "*ratio)+1;");

    script.append("var x = left;");
    boolean ipad = session.getCapabilities().getDevice() == Device.ipad;
    if (ipad) {
        // for ipad, the adress bar h is fixed @ 96px.
        script.append("var y = top+96;");
    } else {
        AppleLocale current = session.getApplication().getCurrentLanguage();
        List<ContentResult> results = session.getApplication().getDictionary(current)
                .getPotentialMatches("Address");
        if (results.size() != 1) {
            log.warning("translation returned " + results.size());
        }
        ContentResult result = results.get(0);
        String addressL10ned = result.getL10nFormatted();
        Criteria c2 = new AndCriteria(new TypeCriteria(UIAElement.class), new NameCriteria(addressL10ned),
                new LabelCriteria(addressL10ned));
        script.append("var addressBar = root.element(-1," + c2.stringify().toString() + ");");
        script.append("var addressBarSize = addressBar.rect();");
        script.append("var delta = addressBarSize.origin.y +39;");
        script.append("if (delta<20){delta=20;};");
        script.append("var y = top+delta;");
    }
    script.append("UIATarget.localTarget().tap({'x':x,'y':y});");
    return script.toString();

}

From source file:org.uiautomation.ios.wkrdp.model.RemoteWebNativeBackedElement.java

License:Apache License

@Override
public Point getLocation() throws Exception {
    // web stuff.
    //scrollIntoViewIfNeeded();
    Point po = findPosition();

    Dimension dim = getInspector().getSize();
    int webPageWidth = getInspector().getInnerWidth();
    if (dim.getWidth() != webPageWidth) {
        log.fine("BUG : dim.getWidth()!=webPageWidth");
    }/*from  w w w  .  j a  v  a  2  s .  c om*/

    Criteria c = new TypeCriteria(UIAWebView.class);
    String json = c.stringify().toString();
    StringBuilder script = new StringBuilder();
    script.append("var root = UIAutomation.cache.get('1');");
    script.append("var webview = root.element(-1," + json + ");");
    script.append("var webviewSize = webview.rect();");
    script.append("var ratio = webviewSize.size.width / " + dim.getWidth() + ";");
    int top = po.getY();
    int left = po.getX();
    script.append("var top = (" + top + "*ratio )+1;");
    script.append("var left = (" + left + "*ratio)+1;");

    script.append("var x = left;");
    boolean ipad = session.getCapabilities().getDevice() == DeviceType.ipad;

    if (isSafari()) {
        if (ipad) {
            // for ipad, the adress bar h is fixed @ 96px.
            script.append("var y = top+96;");
        } else {

            List<ContentResult> results = session.getApplication().getCurrentDictionary()
                    .getPotentialMatches("Address");
            if (results.size() != 1) {
                log.warning("translation returned " + results.size());
            }
            ContentResult result = results.get(0);
            String addressL10ned = result.getL10nFormatted();
            Criteria c2 = new AndCriteria(new TypeCriteria(UIAElement.class), new NameCriteria(addressL10ned),
                    new LabelCriteria(addressL10ned));
            script.append("var addressBar = root.element(-1," + c2.stringify().toString() + ");");
            script.append("var addressBarSize = addressBar.rect();");
            script.append("var delta = addressBarSize.origin.y +39;");
            script.append("if (delta<20){delta=20;};");
            script.append("var y = top+delta;");
        }
    } else {
        Criteria wv = new TypeCriteria(UIAScrollView.class);
        script.append("var webview = root.element(-1," + wv.stringify().toString() + ");");
        script.append("var size = webview.rect();");
        script.append("var offsetY = size.origin.y;");
        // UIAWebView.y
        script.append("var y = top+offsetY;");
        //script.append("var y = top+64;");
    }
    script.append("return new Array(parseInt(x), parseInt(y));");

    Object response = ((JavascriptExecutor) nativeDriver).executeScript(String.valueOf(script));

    int x = ((ArrayList<Long>) response).get(0).intValue();
    int y = ((ArrayList<Long>) response).get(1).intValue();

    return new Point(x, y);
}