I want to get the on screen coordinates of a WebElement and use the robot class to click on it.
SeleniumMethods sl= new SeleniumMethods();
WebDriver driver = new FirefoxDriver();
public void example () throws Exception{
driver.get("http://www.example.com/");
driver.manage().window().maximize();
//Xpath to more Info Link
String xpath = "/html/body/div/p[2]/a";
Robot robot = new Robot();
//Pass in the X and Y Coordinates of the Element (Integer)
robot.mouseMove(driver.findElement(By.xpath(xpath)).getLocation().getX(),driver.findElement(By.xpath(xpath)).getLocation().getY());
robot.mousePress(InputEvent.BUTTON1_MASK);
Thread.sleep(50);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
It think the problem is that the coordinates passed in the mousePress method do not contain the firefox tabs,url bar etc. Is that really my problem? and if so how do I solve it? Thanks in advance!