Java Code Examples for org.openqa.selenium.Rectangle#getY()
The following examples show how to use
org.openqa.selenium.Rectangle#getY() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Edition022_Tap_By_Coords.java From appiumpro with Apache License 2.0 | 5 votes |
public void actualTest(AppiumDriver driver) { WebDriverWait wait = new WebDriverWait(driver, 10); try { // find our reference element WebElement ref = wait .until(ExpectedConditions.presenceOfElementLocated(referenceElement)); // get the location and dimensions of the reference element, and find its center point Rectangle rect = ref.getRect(); int refElMidX = rect.getX() + rect.getWidth() / 2; int refElMidY = rect.getY() + rect.getHeight() / 2; // set the center point of our desired element; we know it is one row above the // reference element so we simply have to subtract the height of the reference element int desiredElMidX = refElMidX; int desiredElMidY = refElMidY - rect.getHeight(); // perform the TouchAction that will tap the desired point TouchAction action = new TouchAction<>(driver); action.press(PointOption.point(desiredElMidX, desiredElMidY)); action.waitAction(WaitOptions.waitOptions(Duration.ofMillis(500))); action.release(); action.perform(); // finally, verify we made it to the login screen (which means we did indeed tap on // the desired element) wait.until(ExpectedConditions.presenceOfElementLocated(username)); } finally { driver.quit(); } }
Example 2
Source File: DeviceUtils.java From Quantum with MIT License | 5 votes |
/** * This function will calculate the location of the element on the device and * manually tap the point location of the middle of the element. This function * accounts that there may be a header to offset from. * * @param loc - locator to find the element to be clicked * @param addressBar - navigation bar that takes up the top half of the device * outside of the webview */ public static void touchObject(String loc, String addressBar) { int bannerY = getOffset(addressBar); int scaleFactor = getScale(); // Gets the rectangle of the element we want to click Rectangle rect = new QAFExtendedWebElement(loc).getRect(); // calculates the middle x value using the rectangle and multiplying the scale int x = (rect.getX() + (rect.getWidth() / 2)) * scaleFactor; // calculates the middle y value using the rectangle, adding the offset // and multiplying the scale int y = (rect.getY() + (rect.getHeight() / 2) + bannerY) * scaleFactor; // Touch the device at the point calculated touch(x + "," + y); }
Example 3
Source File: DeviceUtils.java From Quantum with MIT License | 5 votes |
/** * Gets the offset of the header values to offset y value of the header element * * @param addressBar - header element to measure * @param context - context of the element to use * @return the y offset of the element */ public static int getOffset(String addressBar, String context) { // Stores the current context so we can switch to it at the end String curContext = DeviceUtils.getCurrentContext(); // Switch to native context switchToContext(context); // Gets the rectangle of the welement to get the x,y and width height Rectangle view = new QAFExtendedWebElement(addressBar).getRect(); switchToContext(curContext); // Switch back to the original context // this gets the application size of the area above the viewport // we will use this to offset the element return (view.getY() + view.getHeight()); }
Example 4
Source File: SeleniumTest.java From gatf with Apache License 2.0 | 4 votes |
private static boolean checkRectangleOnTop(Rectangle trec, Rectangle orec) { Point tmid = new Point(trec.getX() + trec.getWidth()/2, trec.getY() + trec.getHeight()/2); return tmid.getX()>orec.getX() && tmid.getX()<(orec.getX()+orec.getWidth()) && tmid.getY()>orec.getY() && tmid.getY()<(orec.getY()+orec.getHeight()); }