Python - pywinauto iface_value.GetValue () Не работает, потому что у выбранного окна нет такого атрибута? - PullRequest
1 голос
/ 21 марта 2020

Я автоматизирую приложение на основе c#, в которое встроены некоторые веб-страницы. И я пытаюсь получить значение данных из таблицы страницы с помощью dlg_list.iface_value.GetValue (), ошибка происходит следующим образом,

D:\app\python\lib\site-packages\comtypes__init__.py", line 275, in getattr
 fixed_name = self.map_case[name.lower()]
 KeyError: 'getvalue'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
 File "D:/app/pyprojects/smart/Patient_Registry/Go2Calling.py", line 9, in dlg_list.iface_value.GetValue()
 File "D:\app\python\lib\site-packages\comtypes__init__.py", line 277, in getattr
 raise AttributeError(name) AttributeError: GetValue

dlg_list является одной из записей, которые могут быть выделены с помощью .draw_outline ( ), Я пытался получить значение записи.

Pywinauto больше не имеет GetValue ()?

Обновление от 24 марта 2020 года:

row1 = dlg.child_window(title="name row 0").wrapper_object()
dir(row1)
D:\app\pyprojects\smart\venv\Scripts\python.exe D:/app/pyprojects/smart/Patient_Registry/Triage.py
['__abstractmethods__', '__class__', '__delattr__', '__dict__', '__dir__',
 '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__',
 '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__',
 '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__',
 '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__',
 '__weakref__', '_abc_impl', '_as_parameter_', '_cache',
 '_calc_click_coords', '_control_types', '_create_wrapper', '_element_info',
 '_needs_image_prop', '_select', 'actions', 'appdata', 'backend',
 'can_be_label', 'can_select_multiple', 'capture_as_image', 'children',
 'children_texts', 'class_name', 'click_input', 'client_to_screen', 'close',
 'collapse', 'container', 'control_count', 'control_id', 'descendants',
 'double_click_input', 'drag_mouse_input', 'draw_outline', 'element_info',
 'expand', 'friendly_class_name', 'friendlyclassname', 'get_expand_state',
 'get_properties', 'get_selection', 'handle', 'has_keyboard_focus',
 'has_title', 'iface_expand_collapse', 'iface_grid', 'iface_grid_item',
 'iface_invoke', 'iface_item_container', 'iface_range_value',
 'iface_scroll_item', 'iface_selection', 'iface_selection_item',
 'iface_table', 'iface_table_item', 'iface_text', 'iface_toggle',
 'iface_value', 'iface_virtualized_item', 'iface_window', 'invoke',
 'is_active', 'is_checked', 'is_child', 'is_collapsed', 'is_dialog',
 'is_enabled', 'is_expanded', 'is_keyboard_focusable', 'is_selected',
 'is_selection_required', 'is_visible', 'maximize', 'menu_select',
 'minimize', 'move_mouse_input', 'parent', 'press_mouse_input', 'process_id',
 'rectangle', 'ref', 'release_mouse_input', 'right_click_input', 'root',
 'select', 'selected_item_index', 'set_focus', 'texts', 'top_level_parent',
 'type_keys', 'verify_actionable', 'verify_enabled', 'verify_visible',
 'wait_for_idle', 'wheel_mouse_input', 'window_text', 'windowclasses',
 'writable_props']

Avery : iface_value есть, но при попытке dlg.child_window(title="name row 0").iface_value.GetValue() полное сообщение об ошибке выглядело так:

D:\app\pyprojects\smart\venv\Scripts\python.exe D:/app/pyprojects/smart/Patient_Registry/Triage.py
Traceback (most recent call last):
  File "D:\app\python\lib\site-packages\comtypes\__init__.py", line 275, in __getattr__
    fixed_name = self.__map_case__[name.lower()]
KeyError: 'getvalue'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:/app/pyprojects/smart/Patient_Registry/Triage.py", line 35, in <module>
    dlg.child_window(title="name row 0").iface_value.GetValue()
  File "D:\app\python\lib\site-packages\comtypes\__init__.py", line 277, in __getattr__
    raise AttributeError(name)
AttributeError: GetValue

Process finished with exit code 1

Я также пытался dir(var.wrapper_object().iface_value), нет GetValue в списке, CurrentValue, кажется, соответствует мое требование.

1 Ответ

0 голосов
/ 24 марта 2020

Ну, ValuePattern и LegacyIAccessiblePattern разные. Если вы запускаете Inspect.exe в режиме «UI Automation» и видите, что для элемента поддерживается устаревший шаблон, вы можете использовать метод объекта-оболочки .legacy_properties(), который возвращает словарь устаревших свойств. Пока эти свойства нельзя использовать в качестве ключевых слов в спецификации .child_window(...) (будет реализовано в следующем основном выпуске). Поддержка

ValuePattern означает, что вам необходим .iface_value.CurrentValue или метод оболочки .get_value().

...