Selenium:使用Python获取元素的坐标或维度

2024-05-15 13:01:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我看到有一些方法可以通过各种用于Selenium的Java库来获取元素的屏幕位置和尺寸,比如org.openqa.selenium.Dimension,它提供.getSize(),以及org.openqa.selenium.PointgetLocation()

有没有任何方法可以通过Selenium Python绑定获得元素的位置或维度?


Tags: 方法org元素屏幕尺寸seleniumjavapoint
1条回答
网友
1楼 · 发布于 2024-05-15 13:01:13

明白了!线索在selenium.webdriver.remote.webelement — Selenium 3.14 documentation.

web元素具有属性.size.location。两者都属于dict类型。

driver = webdriver.Firefox()

e = driver.find_element_by_xpath("//someXpath")

location = e.location
size = e.size

print(location)
print(size)

输出:

{'y': 202, 'x': 165}
{'width': 77, 'height': 22}

它们还有一个名为^{}的属性,它本身就是一个dict,包含元素的sizelocation

相关问题 更多 >