Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

As part of my selenium test for a login function, I would like to click a button by identifying its coordinates, and instructing selenium to click at those coordinates. This would be done without actually identifying the element itself (via id, xpath, etc).

I understand there are other more efficient ways to run a click command, but I'm looking to specifically use this approach to best match the user experience. Thanks.

1 Answer

0 votes
by (62.9k points)

This worked for me in Java for clicking on coordinates irrespective of any elements.

Actions actions = new Actions(driver);

actions.moveToElement(driver.findElement(By.tagName("body")), 0, 0);

actions.moveByOffset(xCoordinate, yCoordinate).click().build().perform();

The second line of code will reset your cursor to the top left corner of the web browser view and the third line of the code will click on the x,y coordinates provided by you manually as the parameter.

Browse Categories

...