I have a mouse position on the screen, for example (10, 10) and I want to translate that posistion to a control. How can I do that?
Example:
from pywinauto.application import Application
app = Application((backend="uia").start("notepad.exe")
dlg = app.top_window()
hardcoded_file_button_rec = dlg.File.rectangle() #<RECT L10, T10, R40, B40>
given_mouse_position = (10, 10)
found_file_button = search_by_position(app, given_mouse_position)
assert hardcoded_file_button_rec == found_file_button.rectangle()
Does pywinauto already has built-in function for that? On this question I found how to iterate over all controls in a window using pywinauto. So iterating over it, I can check if controls[i].rectancle().top == 10 and controls[i].rectancle().left == 10
.
What is the right thing to do?
As well as on StackOverflow:
How to pass POINT structure to ElementFromPoint method in Python?
Clean code sample for any element:
from ctypes.wintypes import tagPOINT
import pywinauto
elem = pywinauto.uia_defines.IUIA().iuia.ElementFromPoint(tagPOINT(x, y))
element = pywinauto.uia_element_info.UIAElementInfo(elem)
wrapper = pywinauto.controls.uiawrapper.UIAWrapper(element)
wrapper
is what you need probably since it's actionable object having methods like .invoke()
etc.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
site design / logo © 2019 Stack Exchange Inc; user contributions licensed under cc by-sa 4.0
with attribution required.
rev 2019.10.4.35123