pywinauto - 如何点击网格中的文本元素

时间:2017-05-25 16:46:15

标签: pywinauto

我需要在网格中单击一下文本,而在此元素中没有click方法,该怎么做?

select_viagem = flight_app.child_window(title="166,80", control_type="Text")
select_viagem.click()

https://github.com/reinaldorossetti/pywinauto/blob/master/exemplo01.py

Traceback (most recent call last):
  File "C:/Users/reinaldo.rossetti/PycharmProjects/pywinauto/exemplo01.py", line 56, in <module>
    select_viagem.click()
  File "C:\Python35\lib\site-packages\pywinauto\application.py", line 171, in __call__
    format(self.criteria[-1]['best_match']))
AttributeError: WindowSpecification class has no 'click' method

    test = {UIAWrapper} <pywinauto.controls.uiawrapper.UIAWrapper object at 0x0000000005BE14E0>
 _abc_cache = {WeakSet} <_weakrefset.WeakSet object at 0x00000000050DF748>
 _abc_negative_cache = {WeakSet} <_weakrefset.WeakSet object at 0x00000000050DF7B8>
 _abc_negative_cache_version = {int} 39
 _abc_registry = {WeakSet} <_weakrefset.WeakSet object at 0x00000000050DF6D8>
 _as_parameter_ = {NoneType} None
 _cache = {dict} {}
 _control_types = {list} <class 'list'>: []
 _element_info = {UIAElementInfo} <pywinauto.uia_element_info.UIAElementInfo object at 0x0000000005BE16A0>
 _needs_image_prop = {bool} False
 actions = {_StandardLogger} <pywinauto.actionlogger._StandardLogger object at 0x0000000005BE1780>
 appdata = {NoneType} None
 backend = {BackEnd} <pywinauto.backend.BackEnd object at 0x00000000050DF828>
 can_be_label = {bool} False
 element_info = {UIAElementInfo} <pywinauto.uia_element_info.UIAElementInfo object at 0x0000000005BE16A0>
 friendlyclassname = {NoneType} None
 handle = {NoneType} None
 has_title = {bool} True
 iface_expand_collapse = {str} 'Traceback (most recent call last):\n  File "C:\\Python35\\lib\\site-packages\\pywinauto\\uia_defines.py", line 217, in get_elem_interface\n    iface = cur_ptrn.QueryInterface(cls_name)\n  File "C:\\Python35\\lib\\site-packages\\comtypes\\__init__.py", line 1
 iface_grid = {str} 'Traceback (most recent call last):\n  File "C:\\Python35\\lib\\site-packages\\pywinauto\\uia_defines.py", line 217, in get_elem_interface\n    iface = cur_ptrn.QueryInterface(cls_name)\n  File "C:\\Python35\\lib\\site-packages\\comtypes\\__init__.py", line 1
 iface_grid_item = {str} 'Traceback (most recent call last):\n  File "C:\\Python35\\lib\\site-packages\\pywinauto\\uia_defines.py", line 217, in get_elem_interface\n    iface = cur_ptrn.QueryInterface(cls_name)\n  File "C:\\Python35\\lib\\site-packages\\comtypes\\__init__.py", line 1
 iface_invoke = {str} 'Traceback (most recent call last):\n  File "C:\\Python35\\lib\\site-packages\\pywinauto\\uia_defines.py", line 217, in get_elem_interface\n    iface = cur_ptrn.QueryInterface(cls_name)\n  File "C:\\Python35\\lib\\site-packages\\comtypes\\__init__.py", line 1
 iface_item_container = {str} 'Traceback (most recent call last):\n  File "C:\\Python35\\lib\\site-packages\\pywinauto\\uia_defines.py", line 217, in get_elem_interface\n    iface = cur_ptrn.QueryInterface(cls_name)\n  File "C:\\Python35\\lib\\site-packages\\comtypes\\__init__.py", line 1
 iface_range_value = {str} 'Traceback (most recent call last):\n  File "C:\\Python35\\lib\\site-packages\\pywinauto\\uia_defines.py", line 217, in get_elem_interface\n    iface = cur_ptrn.QueryInterface(cls_name)\n  File "C:\\Python35\\lib\\site-packages\\comtypes\\__init__.py", line 1
 iface_scroll_item = {str} 'Traceback (most recent call last):\n  File "C:\\Python35\\lib\\site-packages\\pywinauto\\uia_defines.py", line 217, in get_elem_interface\n    iface = cur_ptrn.QueryInterface(cls_name)\n  File "C:\\Python35\\lib\\site-packages\\comtypes\\__init__.py", line 1
 iface_selection = {str} 'Traceback (most recent call last):\n  File "C:\\Python35\\lib\\site-packages\\pywinauto\\uia_defines.py", line 217, in get_elem_interface\n    iface = cur_ptrn.QueryInterface(cls_name)\n  File "C:\\Python35\\lib\\site-packages\\comtypes\\__init__.py", line 1
 iface_selection_item = {str} 'Traceback (most recent call last):\n  File "C:\\Python35\\lib\\site-packages\\pywinauto\\uia_defines.py", line 217, in get_elem_interface\n    iface = cur_ptrn.QueryInterface(cls_name)\n  File "C:\\Python35\\lib\\site-packages\\comtypes\\__init__.py", line 1
 iface_table = {str} 'Traceback (most recent call last):\n  File "C:\\Python35\\lib\\site-packages\\pywinauto\\uia_defines.py", line 217, in get_elem_interface\n    iface = cur_ptrn.QueryInterface(cls_name)\n  File "C:\\Python35\\lib\\site-packages\\comtypes\\__init__.py", line 1
 iface_table_item = {str} 'Traceback (most recent call last):\n  File "C:\\Python35\\lib\\site-packages\\pywinauto\\uia_defines.py", line 217, in get_elem_interface\n    iface = cur_ptrn.QueryInterface(cls_name)\n  File "C:\\Python35\\lib\\site-packages\\comtypes\\__init__.py", line 1
 iface_text = {str} 'Traceback (most recent call last):\n  File "C:\\Python35\\lib\\site-packages\\pywinauto\\uia_defines.py", line 217, in get_elem_interface\n    iface = cur_ptrn.QueryInterface(cls_name)\n  File "C:\\Python35\\lib\\site-packages\\comtypes\\__init__.py", line 1
 iface_toggle = {str} 'Traceback (most recent call last):\n  File "C:\\Python35\\lib\\site-packages\\pywinauto\\uia_defines.py", line 217, in get_elem_interface\n    iface = cur_ptrn.QueryInterface(cls_name)\n  File "C:\\Python35\\lib\\site-packages\\comtypes\\__init__.py", line 1
 iface_value = {str} 'Traceback (most recent call last):\n  File "C:\\Python35\\lib\\site-packages\\pywinauto\\uia_defines.py", line 217, in get_elem_interface\n    iface = cur_ptrn.QueryInterface(cls_name)\n  File "C:\\Python35\\lib\\site-packages\\comtypes\\__init__.py", line 1
 iface_virtualized_item = {str} 'Traceback (most recent call last):\n  File "C:\\Python35\\lib\\site-packages\\pywinauto\\uia_defines.py", line 217, in get_elem_interface\n    iface = cur_ptrn.QueryInterface(cls_name)\n  File "C:\\Python35\\lib\\site-packages\\comtypes\\__init__.py", line 1
 iface_window = {str} 'Traceback (most recent call last):\n  File "C:\\Python35\\lib\\site-packages\\pywinauto\\uia_defines.py", line 217, in get_elem_interface\n    iface = cur_ptrn.QueryInterface(cls_name)\n  File "C:\\Python35\\lib\\site-packages\\comtypes\\__init__.py", line 1
 ref = {NoneType} None
 windowclasses = {list} <class 'list'>: []
 writable_props = {list} <class 'list'>: ['class_name', 'friendly_class_name', 'texts', 'control_id', 'rectangle', 'is_visible', 'is_enabled', 'control_count', 'is_keyboard_focusable', 'has_keyboard_focus']

发送此日志。

1 个答案:

答案 0 :(得分:0)

好的,我已经在我的机器上尝试过这个应用程序并且它可以正常工作(在你的语言环境点上应该用逗号替换):

grid.child_window(title="131.10", control_type="Text").click_input()

网格元素没有InvokePattern,因此方法.invoke()将引发NoPatternInterfaceError。方法.click()只是按钮的.invoke()的别名。但它可能对其他控件类型有不同的含义。这就是我们仅将.invoke()名称用于非按钮控件的原因。