Selenium: get coordinates or dimensions of element with Python

0
0

I see that there are methods for getting the screen position and dimensions of an element through various Java libraries for Selenium, such as org.openqa.selenium.Dimension, which offers .getSize(), and org.openqa.selenium.Point with getLocation().

Is there any way to get either the location or dimensions of an element with the Selenium Python bindings?

  • You must to post comments
0
0

Got it! The clue was on https://seleniumhq.github.io/selenium/docs/api/py/webdriver_remote/selenium.webdriver.remote.webelement.html

WebElements have the properties .size and .location. Both are of type dict.

driver = webdriver.Firefox()
e
= driver.find_element_by_xpath("//someXpath")
location
= e.location
size
= e.size
print(location)
print(size)

Returns:

{'y': 202, 'x': 165}
{'width': 77, 'height': 22}

They also have a property called rect which is itself a dict, and contains the element’s size and location.

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website