本文介绍了[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("stackoverflow/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] 元素在屏幕上的位置
发布评论