List of usage examples for org.openqa.selenium Point Point
public Point(int x, int y)
From source file:org.uiautomation.ios.wkrdp.model.RemoteWebElement.java
License:Apache License
public Point getLocation() throws Exception { String f = "(function(arg) { " + "var loc = " + IosAtoms.GET_LOCATION_IN_VIEW + "(arg);" + "return " + IosAtoms.STRINGIFY + "(loc);})"; JSONArray args = new JSONArray(); args.put(new JSONObject().put("objectId", getRemoteObject().getId())); JSONObject response = getInspectorResponse(f, args, true); String s = inspector.cast(response); JSONObject o = new JSONObject(s); return new Point(o.getInt("x"), o.getInt("y")); }
From source file:org.uiautomation.ios.wkrdp.model.RemoteWebElement.java
License:Apache License
public Point findPosition() throws Exception { StringBuilder b = new StringBuilder(); b.append("(function(){"); b.append("var element = this;\n"); b.append("var rect = element.getClientRects()[0];\n"); b.append("var res = {'x': rect.left, 'y': rect.top};\n"); b.append(" var doc = element.ownerDocument;\n"); b.append(" var win = doc.defaultView;\n"); b.append(" var topWin = win.top;\n"); b.append(" var parentFrame = function (doc) {\n"); b.append(" var win = doc.defaultView;\n"); b.append(" var parentWin = win.parent;\n"); b.append(" var parentDoc = parentWin.document;\n"); b.append(" var frames = parentDoc.querySelectorAll('iframe,frame');\n"); b.append(" for (var i = 0; i < frames.length; i++) {\n"); b.append(" if (frames[i].contentDocument === doc) {\n"); b.append(" var r = frames[i];\n"); b.append(" return r;\n"); b.append(" }\n"); b.append(" }\n"); b.append(" return null;\n"); b.append("}\n"); b.append(" while (win !== topWin) {\n"); b.append(" rect = parentFrame(doc).getClientRects()[0];\n"); b.append(" var xoff = rect.left;\n"); b.append(" var yoff = rect.top;\n"); b.append(" if (xoff > 0) {\n"); b.append(" res.x += xoff;\n"); b.append(" }\n"); b.append(" if (yoff > 0) {\n"); b.append(" res.y += yoff;\n"); b.append(" }\n"); b.append(" win = win.parent;\n"); b.append(" doc = win.document;\n"); b.append("}\n"); b.append("return " + IosAtoms.STRINGIFY + "(res);\n"); b.append("})"); JSONObject response = getInspectorResponse(b.toString(), null, false); String s = inspector.cast(response); JSONObject o = new JSONObject(s); return new Point(o.getInt("x"), o.getInt("y")); }
From source file:org.uiautomation.ios.wkrdp.model.RemoteWebElement.java
License:Apache License
public Point findPositionOld() throws Exception { String f = "(function(a) { " + "var el = this;" + " var rect = el.getClientRects()[0];" + " var res = " + IosAtoms.STRINGIFY + "({'top': rect.top,'left': rect.left });" + "return res;" + "})"; JSONObject response = getInspectorResponse(f, null, false); String s = inspector.cast(response); JSONObject o = new JSONObject(s); return new Point(o.getInt("left"), o.getInt("top")); }
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();/* w ww.j a v a2s .c o m*/ 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 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); }
From source file:org.xframium.device.factory.CachedWebElement.java
License:Open Source License
@Override public Point getLocation() { try {/* w w w . j a v a2 s . co m*/ String x = null, y = null; x = getAttribute("x"); y = getAttribute("y"); return new Point(Integer.parseInt(x), Integer.parseInt(y)); } catch (Exception e) { return webDriver.findElement(by).getLocation(); } }
From source file:org.xframium.gesture.AbstractGesture.java
License:Open Source License
/** * Gets the actual point./*from w w w .j a v a 2s. com*/ * * @param percentagePoint the percentage point * @param screenDimension the screen dimension * @return the actual point */ protected Point getActualPoint(Point percentagePoint, Dimension screenDimension) { if (webElement != null) { if (webElement.getLocation() != null && webElement.getSize() != null && webElement.getSize().getWidth() > 0 && webElement.getSize().getHeight() > 0) { int x = percentagePoint.getX() * webElement.getSize().getWidth() + webElement.getLocation().getX(); int y = percentagePoint.getY() * webElement.getSize().getHeight() + webElement.getLocation().getY(); return new Point(x, y); } } return new Point((int) ((percentagePoint.getX() / 100.0) * (double) screenDimension.getWidth()), (int) ((percentagePoint.getY() / 100.0) * (double) screenDimension.getHeight())); }
From source file:org.xframium.gesture.factory.spi.perfecto.SwipeGesture.java
License:Open Source License
@Override protected boolean _executeGesture(WebDriver webDriver) { String executionId = getExecutionId(webDriver); String deviceName = getDeviceName(webDriver); if (executionId != null && deviceName != null) { if (webElement != null) { if (webElement.getLocation() != null && webElement.getSize() != null && webElement.getSize().getWidth() > 0 && webElement.getSize().getHeight() > 0) { int x = (int) ((getSwipeStart().getX() / 100.0) * (double) webElement.getSize().getWidth() + webElement.getLocation().getX()); int y = (int) ((getSwipeStart().getY() / 100.0) * (double) webElement.getSize().getHeight() + webElement.getLocation().getY()); Point swipeStart = new Point(x, y); x = (int) ((getSwipeEnd().getX() / 100.0) * (double) webElement.getSize().getWidth() + webElement.getLocation().getX()); y = (int) ((getSwipeEnd().getY() / 100.0) * (double) webElement.getSize().getHeight() + webElement.getLocation().getY()); Point swipeEnd = new Point(x, y); PerfectoMobile.instance().gestures().swipe(executionId, deviceName, new PercentagePoint(swipeStart.getX(), swipeStart.getY(), false), new PercentagePoint(swipeEnd.getX(), swipeEnd.getY(), false)); return true; } else { log.warn("A relative elements was specified however no size could be determined"); return false; }// w w w. java 2 s. c o m } PerfectoMobile.instance().gestures().swipe(executionId, deviceName, new PercentagePoint(getSwipeStart().getX(), getSwipeStart().getY()), new PercentagePoint(getSwipeEnd().getX(), getSwipeEnd().getY()), 2); return true; } else return false; }
From source file:org.xframium.gesture.factory.spi.perfecto.TwoFingerGesture.java
License:Open Source License
@Override protected boolean _executeGesture(WebDriver webDriver) { String executionId = getExecutionId(webDriver); String deviceName = getDeviceName(webDriver); if (executionId != null && deviceName != null) { if (webElement != null) { if (webElement.getLocation() != null && webElement.getSize() != null && webElement.getSize().getWidth() > 0 && webElement.getSize().getHeight() > 0) { int x = getStartOne().getX() * webElement.getSize().getWidth() + webElement.getLocation().getX(); int y = getStartOne().getY() * webElement.getSize().getHeight() + webElement.getLocation().getY(); Point swipeStart = new Point(x, y); x = getEndOne().getX() * webElement.getSize().getWidth() + webElement.getLocation().getX(); y = getEndOne().getY() * webElement.getSize().getHeight() + webElement.getLocation().getY(); Point swipeEnd = new Point(x, y); PerfectoMobile.instance().gestures().pinch(executionId, deviceName, new PercentagePoint(swipeStart.getX(), swipeStart.getY(), false), new PercentagePoint(swipeEnd.getX(), swipeEnd.getY(), false)); return true; } else { log.warn("A relative elements was specified however no size could be determined"); return false; }/* w w w . j a v a 2s . c om*/ } PerfectoMobile.instance().gestures().pinch(executionId, deviceName, new PercentagePoint(getStartOne().getX(), getStartOne().getY()), new PercentagePoint(getEndOne().getX(), getEndOne().getY())); return true; } else return false; }
From source file:org.xframium.gesture.GestureManager.java
License:Open Source License
/** * Creates the swipe.// w w w . j av a2 s . c o m * * @param swipeDirection the swipe direction * @return the gesture */ public Gesture createSwipe(Direction swipeDirection) { switch (swipeDirection) { case DOWN: return createSwipe(new Point(50, 15), new Point(50, 85)); case LEFT: return createSwipe(new Point(55, 50), new Point(85, 50)); case RIGHT: return createSwipe(new Point(85, 50), new Point(15, 50)); case UP: return createSwipe(new Point(50, 85), new Point(50, 15)); default: return null; } }
From source file:org.xframium.gesture.GestureManager.java
License:Open Source License
/** * Creates the zoom./*from w ww .j a v a 2 s .c o m*/ * * @return the gesture */ public Gesture createZoom() { return createZoom(new Point(45, 45), new Point(55, 55), new Point(15, 15), new Point(85, 85)); }