pywinauto: Does not work with Win10 Calculator
Under Windows 10, sending keys to the calculator does not work:
>>> import pywinauto
>>> app = pywinauto.Application().start("calc.exe")
>>> app.Window
<pywinauto.application.WindowSpecification object at 0x00000000024B2860>
>>> app.process
5900
>>> app.Window.TypeKeys("2*3=")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\marcio\git\webdriver-python\env\lib\site-packages\pywinauto\application.py", line 252, in __getattr__
ctrls = _resolve_control(self.criteria)
File "C:\Users\marcio\git\webdriver-python\env\lib\site-packages\pywinauto\application.py", line 758, in _resolve_control
raise e.original_exception
pywinauto.findbestmatch.MatchError: Could not find 'Window' in '[]'
>>> app.Calculator.TypeKeys("2*3=")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\marcio\git\webdriver-python\env\lib\site-packages\pywinauto\application.py", line 252, in __getattr__
ctrls = _resolve_control(self.criteria)
File "C:\Users\marcio\git\webdriver-python\env\lib\site-packages\pywinauto\application.py", line 758, in _resolve_control
raise e.original_exception
pywinauto.findbestmatch.MatchError: Could not find 'Calculator' in '[]'
If I use Task Manager, the Calculator pid is 1940 and not 5900.There is not process with pid 5900.
I think this is causing it to find no windows that belong to this app (it filters by process id first).
On the other hand, Notepad works:
>>> app = pywinauto.Application().start("notepad.exe")
>>> app.process
6600
>>> app.Notepad.TypeKeys("2*3=")
<pywinauto.controls.win32_controls.DialogWrapper object at 0x0000000002B22668>
It does type into notepad.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 22 (13 by maintainers)
The problem is not only in minimized state, but I can reproduce it in UIA very easy:
while without
app.Calculator.minimize()
it works.Thanks! Connecting to calc.exe fails:
Connecting to calc seems to work at connecting, but sending keys does not work:
By title works! But I have to use app.Calculator and not app.Window:
I will take a look at the UIA stuff, thanks!
Question: I want to have a utility function to do the work, so app.Calculator does not fly for me. How can I do the same but passing “Calculator” as parameter? Do I have to call findbestmatch directly or is there a nicer way? Thanks!