我试图使用 child_window() func 来获取父节点下的元素但未找到错误。这是父级的 print_control_identifier() 输出:
>>> txb_custom.print_control_identifiers()
Control Identifiers:
Custom - '' (L997, T127, R1075, B177)
['PET WBCustom', 'Custom']
child_window(auto_id="textBox", control_type="Custom")
|
| Edit - 'PET WB' (L997, T127, R1075, B177)
| ['Edit', 'PET WBEdit']
| child_window(title="PET WB", auto_id="textBox", control_type="Edit")
| |
| | ScrollBar - '' (L0, T0, R0, B0)
| | ['ScrollBar', 'ScrollBar0', 'ScrollBar1']
| | child_window(auto_id="VerticalScrollBar", control_type="ScrollBar")
| |
| | ScrollBar - '' (L0, T0, R0, B0)
| | ['ScrollBar2']
| | child_window(auto_id="HorizontalScrollBar", control_type="ScrollBar")
|
| Static - 'PET WB' (L997, T150, R1075, B177)
| ['Static', 'PET WB', 'PET WBStatic']
| child_window(title="PET WB", auto_id="textBlock", control_type="Text")
我运行以下代码来尝试更改编辑控件中的文本并得到错误:
>>> txb_custom.child_window(title="PET WB", auto_id="textBox", control_type="Edit").set_text("test")
Traceback (most recent call last):
File "C:\Program Files\Python38\lib\site-packages\pywinauto\application.py", line 250, in __resolve_control
ctrl = wait_until_passes(
File "C:\Program Files\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 "<pyshell#81>", line 1, in <module>
txb_custom.child_window(title="PET WB", auto_id="textBox", control_type="Edit").set_text("test")
File "C:\Program Files\Python38\lib\site-packages\pywinauto\application.py", line 379, in __getattribute__
ctrls = self.__resolve_control(self.criteria)
File "C:\Program Files\Python38\lib\site-packages\pywinauto\application.py", line 261, in __resolve_control
raise e.original_exception
File "C:\Program Files\Python38\lib\site-packages\pywinauto\timings.py", line 436, in wait_until_passes
func_val = func(*args, **kwargs)
File "C:\Program Files\Python38\lib\site-packages\pywinauto\application.py", line 222, in __get_ctrl
ctrl = self.backend.generic_wrapper_class(findwindows.find_element(**ctrl_criteria))
File "C:\Program Files\Python38\lib\site-packages\pywinauto\findwindows.py", line 87, in find_element
raise ElementNotFoundError(kwargs)
pywinauto.findwindows.ElementNotFoundError: {'title': 'PET WB', 'auto_id': 'textBox', 'control_type': 'Edit', 'top_level_only': False, 'parent': <uia_element_info.UIAElementInfo - '', TextBoxWithEllipsis, None>, 'backend': 'uia'}