How to find out the dimensions of any field in the screen


I am facing the issue while trying to scroll the screen up. I am using the code as below to scroll with just guess on the multiplication factors and can’t seems to work at some times.

Is there an effective/easy way to scroll the screen based on the fields position or any other mechanism.

Please help.

    org.openqa.selenium.Dimension size1 = driver.manage().window().getSize();
    int x1 = size1.getWidth() / 2;
    int starty1 = (int) (size1.getHeight() * 0.40);
    int endy1 = (int) (size1.getHeight() * 0.20);
    driver.swipe(x1, starty1, x1, endy1, 2000);