Answer the question
In order to leave comments, you need to log in
Selenium, js - how to find a DOM element by coordinates?
A strange task has appeared - to find a DOM element by known x and y coordinates.
For example, on any Habr page, if we take ~ 80px for Y and width / 2 for X, then we will click on the logo - this element:
<a title="На главную страницу" href="http://habrahabr.ru/feed/posts/" class="logo "></a>
Answer the question
In order to leave comments, you need to log in
If further it is necessary to perform some actions with this element, then so:
((JavascriptExecutor) webDriver).executeScript("return document.elementFromPoint(100, 200);");
Selenium webdriver has coordinate-by-coordinate click methods (double, contextual, etc.), but I haven’t heard of this to return an element by coordinates. This is what selenium rc usually does.
document.elementFromPoint(document.width / 2, 80)
Probably also in selenium...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question