Selenium: How to click at x,y coordinates?
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();
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 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.
If you want a web element that you can target which encompasses the entire screen, you could try the element that the , , and
browser.actions() .mouseMove( element(by.css('.material-dialog-container')) , -20, -20 // pixel offset from top left ) .click() .perform();
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").Size.Width - 530; int yPosition = this.session.FindElementsByAccessibilityId("GraphicView").Size.Height- 150; actions.MoveToElement(this.xecuteClientSession.FindElementsByAccessibilityId("GraphicView"), xPosition, yPosition).ContextClick().Build().Perform();