How to get coordinates or dimensions of element with Selenium Python?

SeleniumAutomation TestingTesting Tools

We can get coordinates or dimensions of elements with Selenium webdriver. Each of the elements have .size and .location properties which give the x, y coordinates and height, width of the element in the form of a dictionary.

Syntax −

loc = element.location

s = element.size

Let us consider an element for which we shall find coordinates and dimensions−

Example

from selenium import webdriver
driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe")
driver.implicitly_wait(0.5)
driver.get("https://www.tutorialspoint.com/about/about_careers.htm")
#identify element
l= driver.find_element_by_xpath("//img[@class='tp-logo']")
#get x, y coordinates
loc = l.location
#get height, width
s = l.size
print(loc)
print(s)
driver.close()

Output

raja
Published on 18-Sep-2020 12:58:57
Advertisements