title: How to get exact y-coordinate from getLocation in selenium java?
body: <p><strong>Pre-req:</strong></p>
  
  <p>Selenium 3.141</p>
  
  <p>Firefox browser</p>
  
  <p><strong>Requirement</strong>: Get x,y co-ordinates of an webelement and perform mouse move to xy co-ordinates.
  X is calculated properly whereas <strong>y co-ordinate is falling 100 pixel short.</strong></p>
  
  <p><strong>Note</strong>: Webelement Formfield is hidden, user will perform vertical scroll and click on it. Co-ordinates are taken after scrolling.</p>
  
  <pre><code>WebElement fromfield = driver.findElement(By.xpath("//*[contains(@data-field-name,'deliverables')]"));
  jse.executeScript("arguments[0].scrollIntoView();",fromfield); //scroll to the webelement, a small wait is given after scrolling
  
  org.openqa.selenium.Point fromLocation = fromfield.getLocation();
  
  int fromfield_x = fromLocation.x; 
  int fromfield_y = fromLocation.y; //getx/gety returns same values
  
  Actual Output: x = 550, y = 600
  Expected Output: x = 550, y = 700. (**Note**: If I pass 700, then mouse moves correctly to required element, but here y is calculated incorrect)
  </code></pre>
  
  <p>Other trials:Tried with browser open in fullscreen mode but the same issue.</p>
  
  <p>Queries:</p>
  
  <p>How to get exact y co-ordinate? </p>
  
  <p>Is xy co-ordinate calculated from left top corner of desktop window or viewport?</p>
  
  <hr>
  
  <h2>Update</h2>
  
  <p><strong>Status:</strong></p>
  
  <p>Based on your suggestion, I tried below line of code and yes, it automatically scrolls to the required element. </p>
  
  <pre><code>WebElement source = fromfield.findElement(By.xpath(".//*[contains(@title,'test')]"));
   new Actions(driver).moveToElement(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(source))).build().perform();
  </code></pre>
  
  <p><strong>Outcome 1:</strong></p>
  
  <pre><code>System.out.println("Y coordinate is: "+source.getLocation().getY());
  int from_x = source.getLocation().getX();
  int from_y = source.getLocation().getY();
  </code></pre>
  
  <p>I get y co-ords as 700 but the element might be at 900 pixels.</p>
  
  <p>When I do mousemove, it moves to 700 pixels as returned, which is not the element to be dragged. My webelement (source) is still at 900 pixels. X co-ord is completely OK.</p>
  
  <pre><code>robot.mouseMove(from_x , from_y); //moves to 700 pixels
  Actions maction=new Actions(driver);
  Action drag = maction.clickAndHold(source).pause(3000).build();
  drag.perform(); //tries to drag from 700 pixels
  </code></pre>
  
  <p>or</p>
  
  <pre><code>new Actions(driver).moveToElement(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(source))).clickAndHold(source).build().perform();
  </code></pre>
  
  <p>Again y is falling short. What would be the reason? </p>
  
  <p><strong>Outcome 2:</strong>
  Above code snippet (movetoelement) works for chrome but not firefox.</p>