[python][selenium] 元素在屏幕上的位置 [英] [python][selenium] on-screen position of element

查看:21
本文介绍了[python][selenium] 元素在屏幕上的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道某个元素在屏幕上的位置.我知道如何在 Python Selenium webriver 中获取元素的位置,但如何从屏幕的左上角获取偏移量?

I would like to know the on-screen position of some element. I know how to get the position of an element in Python Selenium webriver but how to get an offset from the left-top corner of the screen?

推荐答案

我想仅使用 selenium 无法定义从浏览器窗口左上角到屏幕顶级角的距离.但是您可以尝试实现以下内容:

I guess it's not possible to define distance from top-left corner of browser window to top-level corner of screen with just selenium. But you can try to implement following:

driver = webdriver.Chrome()
driver.maximize_window() # now screen top-left corner == browser top-left corner 
driver.get("http://stackoverflow.com/questions")
question = driver.find_element_by_link_text("Questions")
y_relative_coord = question.location['y']
browser_navigation_panel_height = driver.execute_script('return window.outerHeight - window.innerHeight;')
y_absolute_coord = y_relative_coord + browser_navigation_panel_height
x_absolute_coord = question.location['x']

这篇关于[python][selenium] 元素在屏幕上的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆