niladri chakrabarty niladri chakrabarty - 2 months ago 28x
Python Question

pywinauto.findwindows.WindowNotFoundError in pywinauto

I am new in pywinauto and have just started learning. I have installed pywinauto with pip in my local 32 bit Windows 7 OS.
So, I have this sample code to open an URL in chrome browser.

from pywinauto import application
app.start(r'C:\Program Files\Google\Chrome\Application\chrome.exe')
app.window_(title='New Tab')

On running it, it is throwing error:

Traceback (most recent call last):
File "", line 6, in <module>
File "C:\Python27\lib\site-packages\pywinauto\", line 252, in
ctrls = _resolve_control(self.criteria)
File "C:\Python27\lib\site-packages\pywinauto\", line 758, in _resolve_control
raise e.original_exception

I have googled, but could not find any helpful solution.

Where am I going wrong?


The full answer would be long and complicated. Let's start from your small problem.

  1. Chrome spawns few more processes that is not connected with app object. Solution: use Application().connect(title='New tab') (or title_re or whatever possible for find_windows).

  2. The bigger problem is that Chrome controls cannot be detected and handled by pywinauto 0.5.4 because MS UI Automation support is on the way (70% done in UIA branch on GitHub, see the short intro). By the way, pywinauto/UIA can handle top-level windows in a process-agnostic way: Desktop(backend='uia').NewTab.type_keys('some_URL')

  3. One more detail about Chrome. It doesn't enable UIA support by default. To enable UIA accessibility it must run so: chrome.exe --force-renderer-accessibility. Though UIA mode is enabled by default in Firefox and Opera.

And finally pywinauto is not specifically designed for Web automation. Right now it might be combined with Selenium.