Your ultimate guide

Get Size and Position of a Web Element



How to get a web element's height, width and position using Selenium with Python?
    To get the size and position of a web element using Selenium with Python we will use the 'rect' method. The output will be returned in the form of a Dictionary type.
 
Example:
  1. from selenium import webdriver
  2. from selenium.webdriver.common.by import By

  3. driver = webdriver.Chrome()
  4. driver.get("https://testingcolleges.blogspot.com/2023/08/alerts-demo-pages.html")
  5. element = driver.find_element(By.ID, 'alertbox')
  6. print(element.rect)
Output: {'height': 19, 'width': 57, 'x': 120, 'y': 444}

No comments:

Post a Comment