M
M
Mikhail Konyukhov2013-09-04 21:37:27
JavaScript
Mikhail Konyukhov, 2013-09-04 21:37:27

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>

How to find it using selenium or js knowing its coordinates?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yaroslav Astafiev, 2013-09-04
@piromanlynx

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.

A
Alexander Keith, 2013-09-04
@tenbits

 document.elementFromPoint(document.width / 2, 80) 
Probably also in selenium...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question