Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (27.5k points)

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?

1 Answer

0 votes
by (27.5k points)

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

driver = webdriver.Firefox()

e = driver.find_element_by_xpath("//GiveXpath")

location = e.location

size = e.size

print(location)

print(size)

Output:

{'y': 202, 'x': 165}

{'width': 77, 'height': 22}

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

 

Browse Categories

...