I want to click at x, y coordinates like 52, 216-52, 295.

How can this be done using Selenium? (I am using Mac OSX 10.8.5 with Selenium 2.40.0 and Firefox version 29.0)


You can move the mouse and click with Actions, given you have a element to offset from. You cannot click outside the browser content window or control Operating System elements.

moveToElement(WebElement toElement, int xOffset, int yOffset)
Moves the mouse to an offset from the top-left corner of the element.

The code (Java) would look like this:

Actions builder = new Actions(driver);   
builder.moveToElement(knownElement, 10, 25).click().build().perform();
| improve this answer | |
  • 2
    Can you use the window itself as a known element so that you can click on an absolute x,y position? If so, how do you reference the window? – Doug Sep 13 '14 at 23:21
  • 1
    @Doug I am not sure, but you could try the body element which should start in the upper left corner. If not please ask a new question, because its something new and different. – Niels van Reijmersdal Sep 14 '14 at 8:52
  • 1
    If you want a web element that you can target which encompasses the entire screen, you could try the <html> element that the <head>, <body>, and <footer> exist in. In the past I've used java's Robot library to move the curser to absolute screen positions on my monitor to perform actions. But it's a pretty messy solution since robot doesn't naturally distinguish where your browser window starts and ends. – Julian May 13 '15 at 19:36
  • would there be an equivalent of this in NodeJS? – Malcolm Salvador Jul 13 '18 at 15:08
  • @Malky.Kid The Javascript Selenium API has similar actions, read the documentation here: seleniumhq.github.io/selenium/docs/api/javascript/module/… – Niels van Reijmersdal Jul 14 '18 at 7:48

I needed to do this in javascript with protractor:

    , -20, -20  // pixel offset from top left
| improve this answer | |
  • 2
    i believe it should be mouseMove(element(by.css('.material-dialog-container')), {x: -20, y: -20}) – Dziamid Apr 2 '15 at 10:25

Using MoveToElement you will be able to find or click in whatever point you want, you have just to define the first parameter, it can be the session(winappdriver) or driver(in other ways) which is created when you instance WindowsDriver. Otherwise you can set as first parameter a grid (my case), a list, a panel or whatever you want.

Note: The top-left of your first parameter element will be the position X = 0 and Y = 0

Actions actions = new Actions(this.session);
int xPosition = this.session.FindElementsByAccessibilityId("GraphicView")[0].Size.Width - 530;
int yPosition = this.session.FindElementsByAccessibilityId("GraphicView")[0].Size.Height- 150;
actions.MoveToElement(this.xecuteClientSession.FindElementsByAccessibilityId("GraphicView")[0], xPosition, yPosition).ContextClick().Build().Perform();
| improve this answer | |

Use swipe, except keep x and y locations same for start and end (and make duration really short).

Eg. To touch (540, 905):

driver.swipe(540, 905, 540, 905, 50);

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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