-
Hello, this question is more out of my curiosity then out of need. But I stumbled upon a error: This error shows after: fpoWin.get_toggle_state() fpoWin is a children of a win32 backend application which I accesed by: dsk = Desktop(backend = "win32") In pywinauto documentation I found that get_toggle_state() is a method available to class pywinauto.controls.uia_controls.ButtonWrapper But when I use it I get error saying that its not available for ButtonWrapper. What am I missing here? Does it need to be accessed and specified by app.YourDialog.get_toggle_state() rather then using .children() method? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi! We have met again. In conclusion, the reason is that the backend is set to "win32". >>> # Python==3.10, pywinauto==0.6.8
>>> import pywinauto
>>> from pywinauto import Desktop
>>> import pywinauto.controls
>>> # win32
>>> win32dsk = Desktop(backend="win32")
>>> btn = win32dsk.windows(title='some title')[0].children(class_name='Button')[0]
>>> isinstance(btn, pywinauto.controls.win32_controls.ButtonWrapper)
True
>>> isinstance(btn, pywinauto.controls.uia_controls.ButtonWrapper)
False
>>> btn.get_toggle_state
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'ButtonWrapper' object has no attribute 'get_toggle_state'
>>> # uia
>>> uiadsk = Desktop(backend="uia")
>>> btn = uiadsk.windows(title='some title')[0].children(class_name='Button')[0]
>>> isinstance(btn, pywinauto.controls.win32_controls.ButtonWrapper)
False
>>> isinstance(btn, pywinauto.controls.uia_controls.ButtonWrapper)
True
>>> btn.get_toggle_state
<bound method ButtonWrapper.get_toggle_state of <uia_controls.ButtonWrapper - ...>> The wrapper class instance that returns from methods of In your way, If you want to use a class with a different backend locally, you can instantiate it by passing values to the >>> from pywinauto import win32_element_info
>>> from pywinauto import uia_element_info
>>> win32btn = win32dsk.windows(title='some title')[0].children(class_name='Button')[0]
>>> win32btn
<win32_controls.ButtonWrapper - 'button title', Button, ...>
>>> win32btn.element_info
<win32_element_info.HwndElementInfo - 'button title', Button, ...>
>>> win32btn_elminfo = win32btn.element_info
>>> win32btn_elminfo
<win32_element_info.HwndElementInfo - 'button title', Button, ...>
>>> uiabtn_elminfo = uia_element_info.UIAElementInfo(win32btn_elminfo.handle)
>>> uiabtn_elminfo
<uia_element_info.UIAElementInfo - 'button title', Button, ...>
>>> uiabtn = pywinauto.controls.uia_controls.ButtonWrapper(uiabtn_elminfo)
>>> uiabtn
<uia_controls.ButtonWrapper - 'button title', Button, ...> I had actually planned to use this as a topic for my technical article in the future. I hope this helps. |
Beta Was this translation helpful? Give feedback.
@johnyCZS
Hi!
We have met again.
In conclusion, the reason is that the backend is set to "win32".
To replicate a situation similar to yours, I simulated the GUI of an application in my environment as the target and ran the following steps: