The issue that I have is related to the GetItem() method from pywinauto. I was able to run the window.TreeView.GetItem('\\Desktop').Click() command on Windows 7 and 10 both 32 bit but it throws an exeption and does not run when calling it from the python command line of Windows 10 64 bit.
This is my full code I use:
import pywinauto
pwa_app = pywinauto.application.Application()
w_handle = pywinauto.findwindows.find_windows(title=u'Browse For Folder', class_name='#32770')[0]
window = pwa_app.window_(handle=w_handle)
window.TreeView.GetItem('\\Desktop').Click()
These are the errors that I receive:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\pywinauto\controls\common_controls.py", line 1374, in GetItem
texts = [r.Text() for r in roots]
File "C:\Python27\lib\site-packages\pywinauto\controls\common_controls.py", line 872, in Text
return self._readitem()
File "C:\Python27\lib\site-packages\pywinauto\controls\common_controls.py", line 1263, in _readitem
raise ctypes.WinError()
WindowsError: [Error 0] The operation completed successfully.
Folder Dialog content
I have to mention that I can only access the root of the tree view by window.TreeView.GetItem([0]).Click()
It happens because Win32 API structure sizes for Windows messages are different for 32-bit and 64-bit apps. It's fixed in UIA branch (you can wait for 0.6.0 planned this summer).
Another way is just to set up 32-bit Python (and pywinauto) in addition to your 64-bit Python (you just need to care about full path to python.exe).
Try This one ...
import pywinauto
from pywinauto import Desktop, Application
import pywinauto
app = Application(backend="uia").connect(best_match='File Explorer')
dlg = app.File_Explorer
dlg = dlg.ItemsView.get_item('Documents')
dlg.click_input(double = True)
Related
I want to control python IDLE with pywinauto.
I can start IDLE but cannot input text.
Here is my code:
import pywinauto
app = pywinauto.application.Application(backend="uia").start(r"C:\Python37\pythonw.exe C:\Python37\Lib\idlelib\idle.pyw")
app2 = pywinauto.application.Application().connect(process=app.process)
I tried to use app2.Property.print_control_identifiers() but it returns:
Traceback (most recent call last):
File "C:\Python37\lib\site-packages\pywinauto\application.py", line 256, in __resolve_control
criteria)
File "C:\Python37\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 "<pyshell#9>", line 1, in <module>
app2.Property.print_control_identifiers()
File "C:\Python37\lib\site-packages\pywinauto\application.py", line 595, in print_control_identifiers
this_ctrl = self.__resolve_control(self.criteria)[-1]
File "C:\Python37\lib\site-packages\pywinauto\application.py", line 259, in __resolve_control
raise e.original_exception
File "C:\Python37\lib\site-packages\pywinauto\timings.py", line 436, in wait_until_passes
func_val = func(*args, **kwargs)
File "C:\Python37\lib\site-packages\pywinauto\application.py", line 201, in __get_ctrl
dialog = self.backend.generic_wrapper_class(findwindows.find_element(**criteria[0]))
File "C:\Python37\lib\site-packages\pywinauto\findwindows.py", line 84, in find_element
elements = find_elements(**kwargs)
File "C:\Python37\lib\site-packages\pywinauto\findwindows.py", line 303, in find_elements
elements = findbestmatch.find_best_control_matches(best_match, wrapped_elems)
File "C:\Python37\lib\site-packages\pywinauto\findbestmatch.py", line 533, in find_best_control_matches
raise MatchError(items = name_control_map.keys(), tofind = search_text)
pywinauto.findbestmatch.MatchError: Could not find 'Property' in 'dict_keys(['*Python 3.7.2 Shell*TkTopLevel', '*Python 3.7.2 Shell*', 'TkTopLevel'])'
How to solve the problem?
Thank you.
app = pywinauto.application.Application(backend="uia").start(r"C:\Python37\pythonw.exe C:\Python37\Lib\idlelib\idle.pyw")
app2 = pywinauto.application.Application().connect(process=app.process)
app3 = app2.top_window()
app3.print_control_identifiers()
I doubt that you can do whatever it is that you are trying to do. The pywinauto site says "pywinauto is a set of python modules to automate the Microsoft Windows GUI. At its simplest it allows you to send mouse and keyboard actions to windows dialogs and controls." IDLE uses tkinter, which uses the tcl/tk gui framework. While that ultimately uses Windows graphics, it may not be at the level that pywinauto accesses.
You can use pyautogui which is best for windows GUI automation
I converted RDP connection to automation using pyautogui
import pyautogui
import time
import os
os.system("C:\\Users\Administrator\\Desktop\\RDC.bat")
print(pyautogui.position())
time.sleep(5)
pyautogui.click(490,404)
pyautogui.typewrite("Bitwise$123")
pyautogui.typewrite(["Enter"])
I want to GUI automation of ADS software and for that I am using Python scripting. But I am getting error while working on menu select.
I have tried with SWAPY automation tool to get syntax but no major help from that and then I have tried with below link but still no success. pywinauto: MenuSelect() Cannot be used to select "MenuBar" in some applications. What is a suitable function from this library to use?
>>> from pywinauto.application import Application
>>> import pywinauto
>>> from pywinauto import findwindows
>>> app = pywinauto.Application().start(r"C:\Program Files\Keysight\ADS2020\bin\ads.exe")
>>> app = Application().connect(title=u'Advanced Design System 2020 (Main)', class_name='Qt5QWindowIcon')
>>> MenuItms = app.window_(title=u'Advanced Design System 2020 (Main)').MenuSelect("File->Exit")
Warning (from warnings module):
File "__main__", line 1
DeprecationWarning: Method .window_() is deprecated, use .window() instead.
Warning (from warnings module):
File "__main__", line 1
DeprecationWarning: Method .MenuSelect() is deprecated, use .menu_select() instead.
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
MenuItms = app.window_(title=u'Advanced Design System 2020 (Main)').MenuSelect("File->Exit")
File "C:\Users\aakotkar\AppData\Local\Programs\Python\Python37\lib\site-packages\pywinauto\__init__.py", line 50, in wrap
return method(*args, **kwargs)
File "C:\Users\aakotkar\AppData\Local\Programs\Python\Python37\lib\site-packages\pywinauto\controls\hwndwrapper.py", line 1083, in menu_select
self.menu_item(path, exact=exact).select()
File "C:\Users\aakotkar\AppData\Local\Programs\Python\Python37\lib\site-packages\pywinauto\controls\hwndwrapper.py", line 1028, in menu_item
raise RuntimeError("There is no menu.")
RuntimeError: There is no menu.
It should click on File and then select Exit
I'm developing a desktop app which uses the Mayavi package. So, I'm using anaconda with mayavi 4.4.0 and pyqt 4.11.3 (python 2.7). When I try to save the image using the Mayavi interface I get:
KGlobal::locale(): Warning your global KLocale is being recreated with a valid main component instead of a fake component, this usually means you tried to call i18n related functions before your main component was created. You should not do that since it most likely will not work
Object::connect: No such signal org::freedesktop::UPower::DeviceAdded(QDBusObjectPath)
Object::connect: No such signal org::freedesktop::UPower::DeviceRemoved(QDBusObjectPath)
kfilemodule(5709): couldn't create slave: "Unable to create io-slave:
klauncher said: Unknown protocol ''.
"
Traceback (most recent call last):
File "/home/facu/anaconda/lib/python2.7/site-packages/pyface/ui/qt4/action/action_item.py", line 358, in _qt4_on_triggered
action.perform(action_event)
File "/home/facu/anaconda/lib/python2.7/site-packages/pyface/action/action.py", line 100, in perform
self.on_perform()
File "/home/facu/anaconda/lib/python2.7/site-packages/tvtk/pyface/ui/qt4/decorated_scene.py", line 159, in _save_snapshot
if dialog.open() == OK:
File "/home/facu/anaconda/lib/python2.7/site-packages/pyface/i_dialog.py", line 122, in open
self.close()
File "/home/facu/anaconda/lib/python2.7/site-packages/pyface/ui/qt4/file_dialog.py", line 103, in close
self.wildcard_index = self.control.nameFilters().index(
AttributeError: 'QStringList' object has no attribute 'index'
I have fixed others issues editing *.py files, I don't know how to fix this one in particular .
I need to display notifications in MacOS. Simply running the script with python can display notification. But whenever I pack the script using Pyinstaller, I get the following error. Seems like Pyinstaller is having some problem with working on Mac notifications. I also tried using pync (Python binding for terminal notifier). In all cases, simply running the app python notify.py works, but freezing the script using Pyinstaller doesn't seem to work.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/Library/Python/2.7/site-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/PyObjC/Foundation/__init__.py", line 10, in <module>
from CoreFoundation import *
File "/Library/Python/2.7/site-packages/PyInstaller-2.1-py2.7.egg/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/Users/jacob/mac-notify/build/notify/out00-PYZ.pyz/CoreFoundation", line 19, in <module>
File "/Users/jacob/mac-notify/build/notify/out00-PYZ.pyz/objc._bridgesupport", line 121, in initFrameworkWrapper
File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 939, in resource_exists
File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 1392, in has_resource
File "build/bdist.macosx-10.9-intel/egg/pkg_resources.py", line 1447, in _has
NotImplementedError: Can't perform this operation for unregistered loader type
logout
I am using the following Python script to display notification
import Foundation
import objc
NSUserNotification = objc.lookUpClass('NSUserNotification')
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
notification = NSUserNotification.alloc().init()
notification.setTitle_("TestTitle")
notification.setInformativeText_("This is sample text")
center = NSUserNotificationCenter.defaultUserNotificationCenter()
center.deliverNotification_(notification)
I had similar problems and this is how I made it work. You need not use Foundation as its making the problem with Pyinstaller (Not sure why this is causing an issue) and is not used elsewhere in your code.
import objc
NSUserNotification = objc.lookUpClass('NSUserNotification')
NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
notification = NSUserNotification.alloc().init()
notification.setTitle_("TestTitle")
notification.setInformativeText_("This is sample text")
center = NSUserNotificationCenter.defaultUserNotificationCenter()
center.deliverNotification_(notification)
At this point, it may throw some error or the notification just don't show up. Just add CFBundleIdentifier key into the info.plist file generated by pyinstaller.
At first my running system:
I use Windows 8 Pro and Mayavi 4.3 from the repository together with wxPython 2.9.4.0 at Python 2.7.4 but also had the same issue with mayavi 4.2.1 from the EPD package...
As I try to embedd mayavi into a notebook panel I get some problems with the UI. Even in the demo file from mayavi I got the same strange behavior of external frames generated by mayavi.
So using the settings button a the settings window opens. Also the scene reacts on the parameters I changed using the settings. But after clicking OK or chancel the window does not close. And python gives back several error messages. A simular behavior was there as i used the pipeline by implenting mlab.show_pipeline() command.
This behaivior is could be found on the sample from the enthought web page too.
Here you can see my error message after trying to click OK in the settings frame of the enthougth example:
C:\my_directory\>python wx_embedding.py
C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\wx\toolkit.py:35: wxPyDeprecationWarning: Using deprecated class PySimpleApp.
_app = wx.PySimpleApp()
wx_embedding.py:63: wxPyDeprecationWarning: Using deprecated class PySimpleApp.
app = wx.PySimpleApp()
Traceback (most recent call last): File "C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\wx\ui_live.py", line 360, in _on_ok
self.close( wx.ID_OK )
File "C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\wx\ui_live.py", line 320, in close
ui.finish()
File "C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\ui.py", line 264, in finish
self.reset( destroy = True )
File "C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\ui.py", line 304, in reset
editor.dispose()
File "C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\wx\instance_editor.py", line 208, in dispose
self._ui.dispose()
File "C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\ui.py", line 237, in dispose
self.finish()
File "C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\ui.py", line 264, in finish
self.reset( destroy = True )
File "C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\ui.py", line 318, in reset
toolkit().destroy_children( self.control )
File "C:\Python27\lib\site-packages\enthougth_development_mayavi_git\traitsui\traitsui\wx\toolkit.py", line 474, in destroy_children
control.DestroyChildren()
File "C:\Python27\lib\site-packages\wx-2.9.4-msw\wx\_core.py", line 9203, in DestroyChildren
return _core_.Window_DestroyChildren(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "GetEventHandler() == this" failed at . .\..\src\common\wincmn.cpp(468) in wxWindowBase::~wxWindowBase(): any pushed event handlers must have been removed
Thanks in advance
Mayvi is not compatible with wx 2.9.
More info here: https://support.enthought.com/entries/22601196-wxPython
Please use enpkg to revert to wx 2.8 which ships with EPD.
At least this particular exception can be solved with the changes associated with this PR: https://github.com/enthought/traitsui/pull/108. I don't know about Mayavi and the rest of the stack yet, but that change will at least get traitsui working with wxPython 2.9.