Get element at position with Selenium

Is it possible to run or get the same functionality that is provided document.elementFromPoint

with Selenium web reseller?


source to share

1 answer

To do this, you must use JavaScript:

element = driver.execute_script("""
return document.elementFromPoint(arguments[0], arguments[1]);
""", x, y)


This assumes that x

and are y

set to integer values. The arguments you pass execute_script

after the first argument become arguments[0], arguments[1]

, etc. On the JavaScript side. (This is just plain old arguments

. Selenium wraps JavaScript code that you pass execute_script

to functions.) element

Will be either an instance WebElement

or None

if nothing is found. According to



All Articles