Package org.openqa.selenium

Examples of org.openqa.selenium.Point


  @Override
  public Response handle() throws Exception {
    String ref = getRequest().getVariableValue(":reference");
    RemoteWebNativeBackedElement element = (RemoteWebNativeBackedElement) getWebDriver().createElement(ref);
    Point location = element.getLocation(RemoteWebElement.ElementPosition.TOP_LEFT);
    Response res = new Response();
    res.setSessionId(getSession().getSessionId());
    res.setStatus(0);
    res.setValue(location);
    return res;
View Full Code Here


      NodeId nodeId = RemoteIOSWebDriver.plainNodeId(elementId);
      setJS(plainTemplate.generate(request.getSession(), nodeId.getId()));
    } else {
      Dimension screenSize = getNativeDriver().getScreenSize();
      RemoteWebNativeBackedElement element = (RemoteWebNativeBackedElement) getWebDriver().createElement(elementId);
      Point tapPoint = element.getLocation(RemoteWebElement.ElementPosition.CENTER);
      tapPoint = CoordinateUtils.forcePointOnScreen(tapPoint, screenSize);
      setJS(nativeTemplate.generate(request.getSession(), tapPoint.getX(), tapPoint.getY()));
    }
  }
View Full Code Here

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

    JSONObject payload = request.getPayload();
    Dimension screenSize = getNativeDriver().getScreenSize();
    Point offset = new Point(payload.getInt("xoffset"), payload.getInt("yoffset"));
    String elementId = payload.optString("element");
    if (!payload.isNull("element") && !elementId.equals("")) {
      if (RemoteIOSWebDriver.isPlainElement(elementId)) {
        NodeId nodeId = RemoteIOSWebDriver.plainNodeId(elementId);
        plainScrollFromElement(request, screenSize, nodeId.getId(), offset);
View Full Code Here

  }

  private void nativeScrollFromElement(WebDriverLikeRequest request, Dimension screenSize, String elementId,
                                       Point offset) throws Exception {
    RemoteWebNativeBackedElement element = (RemoteWebNativeBackedElement) getWebDriver().createElement(elementId);
    Point fromPoint = element.getLocation(RemoteWebElement.ElementPosition.CENTER);
    fromPoint = CoordinateUtils.forcePointOnScreen(fromPoint, screenSize);
    Point toPoint = new Point(
        fromPoint.getX() + offset.getX(),
        fromPoint.getY() + offset.getY());
    toPoint = CoordinateUtils.forcePointOnScreen(toPoint, screenSize);
    setJS(nativeFromElementTemplate.generate(
        request.getSession(),
        fromPoint.getX(),
        fromPoint.getY(),
        toPoint.getX(),
        toPoint.getY()));
  }
View Full Code Here

        toPoint.getX(),
        toPoint.getY()));
  }

  private void scrollFromCenter(WebDriverLikeRequest request, Dimension screenSize, Point offset) {
    Point fromPoint = CoordinateUtils.getScreenCenter(screenSize);
    Point toPoint = new Point(fromPoint.getX() + offset.getX(), fromPoint.getY() + offset.getY());
    toPoint = CoordinateUtils.forcePointOnScreen(toPoint, screenSize);
    setJS(fromCenterTemplate.generate(
        request.getSession(),
        fromPoint.getX(),
        fromPoint.getY(),
        toPoint.getX(),
        toPoint.getY()));
  }
View Full Code Here

    JSONObject payload = request.getPayload();
    Dimension screenSize = getNativeDriver().getScreenSize();
    String elementId = payload.optString("element");
    if (!payload.isNull("element") && !elementId.equals("")) {
      Point offset = new Point(payload.getInt("xoffset"), payload.getInt("yoffset"));
      double speed = payload.optDouble("speed", 1.0);
      if (RemoteIOSWebDriver.isPlainElement(elementId)) {
        NodeId nodeId = RemoteIOSWebDriver.plainNodeId(elementId);
        plainFlickFromElement(request, screenSize, offset, speed, nodeId.getId());
      } else {
View Full Code Here

  }

  private void nativeFlickFromElement(WebDriverLikeRequest request, Dimension screenSize, Point offset, double speed,
                                      String elementId) throws Exception {
    RemoteWebNativeBackedElement element = (RemoteWebNativeBackedElement) getWebDriver().createElement(elementId);
    Point fromPoint = element.getLocation(RemoteWebElement.ElementPosition.CENTER);
    Point toPoint = new Point(fromPoint.getX() + offset.getX(), fromPoint.getY() + offset.getY());
    fromPoint = CoordinateUtils.forcePointOnScreen(fromPoint, screenSize);
    toPoint = CoordinateUtils.forcePointOnScreen(toPoint, screenSize);
    int dx = toPoint.getX() - fromPoint.getX();
    int dy = toPoint.getY() - fromPoint.getY();
    double distance = Math.sqrt(dx*dx + dy*dy);
    double duration = distance / speed;
    setJS(fromToTemplate.generate(
        request.getSession(),
        fromPoint.getX(),
        fromPoint.getY(),
        toPoint.getX(),
        toPoint.getY(),
        duration));
  }
View Full Code Here

        toPoint.getY(),
        duration));
  }

  private void flickFromCenter(WebDriverLikeRequest request, Dimension screenSize, double speedX, double speedY) {
    Point fromPoint = CoordinateUtils.getScreenCenter(screenSize);

    // Convert "flick from center at given speed vector" to "drag from center to edge for duration".
    double duration = Math.min(
        fromPoint.getX() / Math.abs(speedX),
        fromPoint.getY() / Math.abs(speedY));
    Point toPoint = new Point(
        (int)(fromPoint.getX() + speedX * duration),
        (int)(fromPoint.getY() + speedY * duration));
    toPoint = CoordinateUtils.forcePointOnScreen(toPoint, screenSize);
    setJS(fromToTemplate.generate(
        request.getSession(),
        fromPoint.getX(),
        fromPoint.getY(),
        toPoint.getX(),
        toPoint.getY(),
        duration));
  }
View Full Code Here

      NodeId nodeId = RemoteIOSWebDriver.plainNodeId(elementId);
      setJS(plainTemplate.generate(request.getSession(), nodeId.getId()));
    } else {
      Dimension screenSize = getNativeDriver().getScreenSize();
      RemoteWebNativeBackedElement element = (RemoteWebNativeBackedElement) getWebDriver().createElement(elementId);
      Point tapPoint = element.getLocation(RemoteWebElement.ElementPosition.CENTER);
      tapPoint = CoordinateUtils.forcePointOnScreen(tapPoint, screenSize);
      setJS(nativeTemplate.generate(request.getSession(), tapPoint.getX(), tapPoint.getY()));
    }
  }
View Full Code Here

  @Override
  public Point getLocation(ElementPosition position)
      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");
    }

    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 ratioX = 1.0 * webviewSize.size.width / " + dim.getWidth() + ";");
    script.append("var ratioY = 1.0 * webviewSize.size.height / " + dim.getHeight() + ";");
    int top = po.getY();
    int left = po.getX();
    // switch +1 to +2 in next, with +1 some clicks in text fields didn't bring up the
    // keyboard, the text field would get focus, but the keyboard would not launch
    // also with this change 17 miscellaneous selenium tests got fixed
    switch (position) {
      case TOP_LEFT: {
        script.append("var top = (" + top + "*ratioX);");
        script.append("var left = (" + left + "*ratioY);");
        break;
      }
      case CENTER: {
        Dimension size = getSize();
        script.append("var top = (" + top + " + " + size.getHeight() + " / 2) * ratioX;");
        script.append("var left = (" + left + " + " + size.getWidth() + " / 2) * ratioY;");
        break;
      }
    }

    script.append("var x = left;");
    boolean ipad = session.getCapabilities().getDevice() == DeviceType.ipad;
    boolean ios7 = new IOSVersion(session.getCapabilities().getSDKVersion()).isGreaterOrEqualTo("7.0");
    boolean ios8 = new IOSVersion(session.getCapabilities().getSDKVersion()).isGreaterOrEqualTo("8.0");

    if (ios8) {
      if (isSafari()) {
        // the first button in the second view for iOS8 safari is the height of the address bar
        script.append("top += root.elements()[1].elements()[0].rect().size.height;");
      }
      script.append("var y = top;");
    } else if (ios7) {
      script.append("var y = webviewSize.origin.y + top;");
      if (isSafari()) {
        script.append("var orientation = UIATarget.localTarget().deviceOrientation();");
        script.append("var plus = orientation == UIA_DEVICE_ORIENTATION_LANDSCAPELEFT || orientation == UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN;");
        // TODO: why is the webView shifted by 20
        script.append("y += plus? 20 : -20;");
      }
    } else {
      if (isSafari()) {
        if (ipad) {
          // for ipad, the adress bar h is fixed @ 96px.
          script.append("var y = top+96;");
        } else {
          ImmutableList<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);
  }
View Full Code Here

TOP

Related Classes of org.openqa.selenium.Point

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.