如何通过 Selenium Python 获取元素的坐标或尺寸?
我们可以通过 Selenium 网页驱动获得元素的坐标或尺寸。每个元素都有 .size 和 .location 属性,其中以字典的形式给出了 x、y 坐标以及宽高。
语法 −
loc = element.location
s = element.size
我们来考虑一个元素,我们将找到它的坐标和尺寸−
示例
from selenium import webdriver
driver = webdriver.Chrome(executable_path="C:\chromedriver.exe")
driver.implicitly_wait(0.5)
driver.get("https://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()输出

广告
数据结构
网络
关系型数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP