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)
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It only takes a minute to sign up.Sign up to join this community
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();
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();
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);