The Selenium Javadoc for Actions.moveToElement
indicate that the meanings of the xOffset
and yOffset
arguments are as follows.
xOffset - Offset from the top-left corner. A negative value means coordinates left from the element.
yOffset - Offset from the top-left corner. A negative value means coordinates above the element.
Consider the following program, run on Linux against Firefox Quantum.
public class FirefoxTest {
public static void main(String[] args) {
// Set up driver
WebDriver driver = new FirefoxDriver();
JavascriptExecutor js = (JavascriptExecutor) driver;
driver.get("http://www.google.com");
WebElement element = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.name("q")));
// Perform a move and click action to see where it lands.
Actions moveAndClick = new Actions(driver).moveToElement(element,0,0).doubleClick();
moveAndClick.perform();
}
}
When the following program is run, the double-click occurs in the middle of the search box rather than at the top left corner (I know this because I injected JS to log the location of the click). Moreover, the following message is output in the terminal where the program is run.
org.openqa.selenium.interactions.Actions moveToElement
INFO: When using the W3C Action commands, offsets are from the center of element
Is it possible to programmatically determine whether the offsets are from the center or the top-left corner of the element for Actions.moveToElement
?