Java Code Examples for org.openqa.selenium.WebElement#getRect()

The following examples show how to use org.openqa.selenium.WebElement#getRect() . 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 vote down vote up
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: Edition090_Image_Element_Optimization.java    From appiumpro with Apache License 2.0 5 votes vote down vote up
private void shootBird(AndroidDriver driver, WebElement birdEl, int xOffset, int yOffset) {
    Rectangle rect = birdEl.getRect();
    Point start = new Point(rect.x + rect.width / 2, rect.y + rect.height / 2);
    Point end = start.moveBy(xOffset, yOffset);
    Duration dragDuration = Duration.ofMillis(750);

    PointerInput finger = new PointerInput(Kind.TOUCH, "finger");
    Sequence shoot = new Sequence(finger, 0);
    shoot.addAction(finger.createPointerMove(Duration.ofMillis(0), Origin.viewport(), start.x, start.y));
    shoot.addAction(finger.createPointerDown(MouseButton.LEFT.asArg()));
    shoot.addAction(finger.createPointerMove(dragDuration, Origin.viewport(), end.x, end.y));
    shoot.addAction(finger.createPointerUp(MouseButton.LEFT.asArg()));
    driver.perform(Arrays.asList(shoot));
}
 
Example 3
Source File: Edition109_iPadOS_Split_Screen.java    From appiumpro with Apache License 2.0 4 votes vote down vote up
protected Rectangle getDockIconRect(String appName) {
    By iconLocator = By.xpath("//*[@name='Multitasking Dock']//*[@name='" + appName + "']");
    WebElement icon = wait.until(
        ExpectedConditions.presenceOfElementLocated(iconLocator));
    return icon.getRect();
}
 
Example 4
Source File: Edition067_Zoom_Touch_Gestures.java    From appiumpro with Apache License 2.0 4 votes vote down vote up
@Test
public void ZoomInAndOut() throws InterruptedException {
    // tap center to dismiss toolbars
    WebElement map = driver.findElementById("com.google.android.apps.maps:id/mainmap_container");
    map.click();

    Rectangle mapCoordinates = map.getRect();
    Point center = getCenter(mapCoordinates);

    driver.perform(zoomOut(center, 450));

    Thread.sleep(1000);

    driver.perform(zoomIn(center, 450));

    Thread.sleep(1000);

    driver.perform(zoomOut(center.moveBy(0, 250), 300));

    Thread.sleep(1000);

    driver.perform(zoomIn(center.moveBy(0, -250), 300));

    Thread.sleep(3000);
}
 
Example 5
Source File: SmartWebElement.java    From blueocean-plugin with MIT License 4 votes vote down vote up
@Override
public Rectangle getRect() {
    WebElement e = getElement();
    return e.getRect();
}
 
Example 6
Source File: GetElementRect.java    From selenium with Apache License 2.0 4 votes vote down vote up
@Override
public Rectangle call() {
  WebElement element = getElement();
  return element.getRect();
}