Get coordinates or dimensions of element with Python using Selenium WebDriver

0 votes
I see that there are methods for getting the 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 a way to get the location or dimensions of an element using Selenium Python bindings?
Jul 11, 2018 in Selenium by QueenBee
• 1,810 points
1,252 views

1 answer to this question.

0 votes

WebElements have the 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)

Returns:

{'y': 200, 'x': 125}
{'width': 87, 'height': 32}

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

answered Jul 11, 2018 by Meci Matt
• 9,400 points

Related Questions In Selenium

0 votes
2 answers

How to get HTML Source of WebElement in Selenium WebDriver using Python?

You can read innerHTML attribute to get source of ...READ MORE

answered Jun 13, 2018 in Selenium by Samarpit
• 5,130 points
10,786 views
0 votes
1 answer
0 votes
2 answers
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
257 views
0 votes
1 answer
0 votes
1 answer

What is the role of TestNG & JUnit frameworks in Selenium?

Well TestNG and JUnit are test frameworks ...READ MORE

answered Apr 18, 2018 in Selenium by king_kenny
• 3,590 points
191 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
623 views
0 votes
1 answer

How do I get current URL in Selenium Webdriver using Python?

Use current_url element. Example: print browser.current_url READ MORE

answered Aug 8, 2018 in Selenium by Meci Matt
• 9,400 points
3,915 views
0 votes
1 answer

XPath for the elements with no ID or Name in Selenium Webdriver

Use like this or similar to this: //div[@id="top-level-menu-item-3"]/div[@class="filter-label"] //div[@id="top-level-menu1"] ...READ MORE

answered Apr 17, 2018 in Selenium by Meci Matt
• 9,400 points
975 views