[python][selenium] 元素在屏幕上的位置

编程入门 行业动态 更新时间:2024-10-28 22:25:54
本文介绍了[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] 元素在屏幕上的位置

本文发布于:2023-10-07 20:09:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1470415.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:元素   位置   屏幕上   python   selenium

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!