Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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)

share|improve this question

2 Answers 2

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();
share|improve this answer
    
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
    
@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 Cleary May 13 at 19:36

I needed to do this in javascript with protractor:

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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