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=application.Application()
app.start(r'C:\Program Files\Google\Chrome\Application\chrome.exe')
app.window_(title='New Tab')
app.window_().TypeKeys('{F6}')
app.window_().TypeKeys('{ESC}')
app.window_().TypeKeys('www.facebook.com')
On running it, it is throwing error:
Traceback (most recent call last):
File "pywinauto_nil.py", line 6, in <module>
app.window_().TypeKeys('{F6}')
File "C:\Python27\lib\site-packages\pywinauto\application.py", line 252, in
__getattr__
ctrls = _resolve_control(self.criteria)
File "C:\Python27\lib\site-packages\pywinauto\application.py", line 758, in _resolve_control
raise e.original_exception
pywinauto.findwindows.WindowNotFoundError
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.
Chrome spawns few more processes that is not connected with app
object. Solution: use Application(backend="uia").connect(title='New tab')
(or title_re
or whatever possible for find_windows).
The bigger problem is that Chrome controls cannot be detected and handled by default backend="win32"
(or pywinauto 0.5.4 and before). MS UI Automation support has been introduced since 0.6.0. By the way, pywinauto/UIA can handle top-level windows in a process-agnostic way: Desktop(backend='uia').NewTab.type_keys('some_URL')
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.