Selenium: click on the element with specific coordinates

Last updated on:

click()
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

robot.mouseMove(coordinates.getX(),coordinates.getY()+120);

// Perform click

Actions builder = new Actions(driver);
   builder.keyDown(Keys.CONTROL)
       .click(someElement)
       .keyUp(Keys.CONTROL);

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

WebElement element = driver.findElement(By.id("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.