Selenium:使用Python获取元素的坐标或尺寸
我看到有通过各种Java库的selenium,如让一个元素的屏幕位置和尺寸的方法org.openqa.selenium.Dimension,提供.getSize()和org.openqa.selenium.Point使用getLocation()。
有什么方法可以使用Selenium Python绑定来获取元素的位置或尺寸?
回答:
得到它了!线索在selenium.webdriver.remote.webelement上— Selenium
3.14文档。
WebElement具有属性.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}
它们还有一个称为的属性rect,其本身就是a
dict,并且包含元素的size和location。
以上是 Selenium:使用Python获取元素的坐标或尺寸 的全部内容, 来源链接: utcz.com/qa/432344.html

