-
-
Save vasily-v-ryabov/e5f927908d424bad422b to your computer and use it in GitHub Desktop.
| # Requirements: | |
| # - Win7 or Win8.1 x64, 64-bit Python | |
| # - pywinauto 0.5.2+ | |
| # - UAC is fully disabled | |
| from __future__ import print_function | |
| import pywinauto | |
| pywinauto.Application().Start(r'explorer.exe') | |
| explorer = pywinauto.Application().Connect(path='explorer.exe') | |
| # Go to "Control Panel -> Programs and Features" | |
| NewWindow = explorer.Window_(top_level_only=True, active_only=True, class_name='CabinetWClass') | |
| try: | |
| NewWindow.AddressBandRoot.ClickInput() | |
| NewWindow.TypeKeys(r'Control Panel\Programs\Programs and Features{ENTER}', with_spaces=True, set_foreground=False) | |
| ProgramsAndFeatures = explorer.Window_(top_level_only=True, active_only=True, title='Programs and Features', class_name='CabinetWClass') | |
| # wait while list of programs is loading | |
| explorer.WaitCPUUsageLower(threshold=5) | |
| item_7z = ProgramsAndFeatures.FolderView.GetItem('7-Zip 9.20 (x64 edition)') | |
| item_7z.EnsureVisible() | |
| item_7z.ClickInput(button='right', where='icon') | |
| explorer.PopupMenu.MenuItem('Uninstall').Click() | |
| Confirmation = explorer.Window_(title='Programs and Features', class_name='#32770', active_only=True) | |
| if Confirmation.Exists(): | |
| Confirmation.Yes.ClickInput() | |
| Confirmation.WaitNot('visible') | |
| WindowsInstaller = explorer.Window_(title='Windows Installer', class_name='#32770', active_only=True) | |
| if WindowsInstaller.Exists(): | |
| WindowsInstaller.WaitNot('visible', timeout=20) | |
| SevenZipInstaller = explorer.Window_(title='7-Zip 9.20 (x64 edition)', class_name='#32770', active_only=True) | |
| if SevenZipInstaller.Exists(): | |
| SevenZipInstaller.WaitNot('visible', timeout=20) | |
| if '7-Zip 9.20 (x64 edition)' not in ProgramsAndFeatures.FolderView.Texts(): | |
| print('OK') | |
| finally: | |
| NewWindow.Close() |
@vasily-v-ryabov Traceback when running the above script in PyWinAuto version 0.6.8 and windows 20H2(OS Build 19042.985)
C:/Users/admin/PycharmProjects/Tool_sanity/scratch_py.py:8: DeprecationWarning: Method .Start() is deprecated, use .start() instead.
pywinauto.Application().Start(r'explorer.exe')
C:/Users/admin/PycharmProjects/Tool_sanity/scratch_py.py:9: DeprecationWarning: Method .Connect() is deprecated, use .connect() instead.
explorer = pywinauto.Application().Connect(path='explorer.exe')
C:/Users/admin/PycharmProjects/Tool_sanity/scratch_py.py:12: DeprecationWarning: Method .Window_() is deprecated, use .window() instead.
NewWindow = explorer.Window_(top_level_only=True, active_only=True, class_name='CabinetWClass')
Traceback (most recent call last):
File "C:\Python38\lib\site-packages\pywinauto\application.py", line 250, in __resolve_control
ctrl = wait_until_passes(
File "C:\Python38\lib\site-packages\pywinauto\timings.py", line 458, in wait_until_passes
raise err
pywinauto.timings.TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):File "C:/Users/admin/PycharmProjects/Tool_sanity/scratch_py.py", line 42, in
NewWindow.Close()
File "C:\Python38\lib\site-packages\pywinauto\application.py", line 396, in getattribute
ctrls = self.__resolve_control(self.criteria)
File "C:\Python38\lib\site-packages\pywinauto\application.py", line 261, in __resolve_control
raise e.original_exception
File "C:\Python38\lib\site-packages\pywinauto\timings.py", line 436, in wait_until_passes
func_val = func(*args, **kwargs)
File "C:\Python38\lib\site-packages\pywinauto\application.py", line 203, in __get_ctrl
dialog = self.backend.generic_wrapper_class(findwindows.find_element(**criteria[0]))
File "C:\Python38\lib\site-packages\pywinauto\findwindows.py", line 87, in find_element
raise ElementNotFoundError(kwargs)
pywinauto.findwindows.ElementNotFoundError: {'top_level_only': True, 'active_only': True, 'class_name': 'CabinetWClass', 'backend': 'win32', 'process': 20396}Process finished with exit code 1
Hi @renatoramossilva maybe this example is a little bit outdated because Win10 had several updates (probably in UI as well). I'm planning to re-check all the examples before next major release (probably this winter).
Anyway full traceback with the error would be useful.