I'm currently using a robot to click at a location on the screen as I've had issues with clicking a button that has a specific ID. e.g. Button_1401. This works fine up to a point, a few problems I've encountered so far have been scrolling the page/ a pop-up covering the browser/ screen resolution size.

I've been thinking of possibly moving the firefox window to the front before using the robot click each time but this seems like a slow process. Is it possible to tell the robot to click the X, Y of the browser itself?

I have tried using Actions.moveToElement but clicking the button even with the correct co-ordinates to offset to I get errors.

  • a robot = a script? a robot = robot framework?
    – Yu Zhang
    Jul 27, 2016 at 11:25
  • a script? maybe I'm not sure to be honest, Just been trying things out and its worked so far Robot robot = new Robot(); robot.mouseMove(151, 700); robot.mousePress(InputEvent.BUTTON1_MASK); robot.mouseRelease(InputEvent.BUTTON1_MASK);
    – N Grabham
    Jul 27, 2016 at 11:25
  • what exceptions did you get?
    – Yu Zhang
    Jul 27, 2016 at 11:26
  • None, The code itself works for what I'm doing right now. the issue I was getting with Actions.moveToElement was about offsetting from a current static button to the ID specific button. Which would throw an exception of something like, the button you are trying to click 'button_1404' is not clickable. Im not really sure I tried it last week.
    – N Grabham
    Jul 27, 2016 at 11:28

1 Answer 1


There IS a way to click on a certain coordinates (X, Y), but you need to locate an element as the reference first.

Can you please try this approach?

Actions builder = new Actions(driver);   
builder.moveToElement(referenceElement, X, Y).click().build().perform();

where X and Y are the offsets from the reference element.

  • Hi, I had previously tried this. The button ID is Button_1404 but to the left of this is a button with a static ID of button I tried: builder.moveToElement(button, 0, 100).click().build().perform(); but when the click is performed I get an error
    – N Grabham
    Jul 27, 2016 at 11:57
  • sorry I mean 100, 0
    – N Grabham
    Jul 27, 2016 at 12:03
  • This is what I tried previously WebElement link = driver.findElement(By.id("button")); Actions builder = new Actions(driver); builder.moveToElement(link, 200, 10).click().perform(); builder.moveToElement(link, 200, 10).release().perform();
    – N Grabham
    Jul 27, 2016 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.