Selenium: click on the element with specific coordinates

Last updated on:

Clicks at the current mouse location.

Before you click on some element you need to point mouse in right place, to be able to do it I would suggest to use Robot

// Robot to point mouse

Point coordinates = driver.findElement(By.cssSelector("#cssSelector")).getLocation();
Robot robot = new Robot();

// Find location for element

int x = driver.findElement(By.cssSelector("#ext-comp-1271")).getLocation().getX();
int y = driver.findElement(By.cssSelector("#ext-comp-1271")).getLocation().getY();

// Move Mouse


// Perform click

Actions builder = new Actions(driver);

You can also try using the Javascript as alternative method for clicking

WebElement element = driver.findElement("something"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);

Selenium Java Doc

View Comments

Leave a Comment

Use markdown or basic HTML and be nice.