I'm aware how to retrieve the coordinates of a web element in Selenium:
WebElement element = driver.findElement(By.xpath(XPath));
Point location = element.getLocation();
location.x + " " + location.y
However I'm trying to do the opposite - locate a web element using its coordinates.
I understand I could find all elements on a web page, loop through the list of elements, get the x,y coordinates of each element in the list and compare it to the expected coordinates. If both x and y coordinates of an element match the expected web element I could return the given web element. However it seems very inefficient to me to need to loop through every web element on a page to find the one matching element.
Is there a more of a direct way of finding an element by coordinates?
Note: Although a similar question has been asked over here: Get element at specified position - JavaScript - my question is different bec I want to be able to do this directly using Selenium without the need to come onto Javscript.