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:
- from selenium import webdriver
- from selenium.webdriver.common.by import By
- driver = webdriver.Chrome()
- driver.get("https://testingcolleges.blogspot.com/2023/08/alerts-demo-pages.html")
- element = driver.find_element(By.ID, 'alertbox')
- print(element.rect)
Output: {'height': 19, 'width': 57, 'x': 120, 'y': 444}
No comments:
Post a Comment