pywinauto:type\键将文本发送到错误的文本框

2024-10-02 16:21:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用pywinauto将文本输入到“开始行”文本框中

enter image description here

我使用以下代码:

import pywinauto from pywinauto.application import Application app = Application().connect(title='HD Die Tester') app['HD Die Tester'].TkChild9.type_keys("hello")

但是,文本显示在“开始列(x)”文本框中。这是我上次点击的那个。你知道吗

enter image description here

也就是说,如果我想让文本出现在TkChild9文本字段中,我必须手动单击它,文本才会出现在那里。我试图做一个自动点击,但没有工作。你知道吗

这是我感兴趣的Gui的类树:

app['HD Die Tester'].PrintControlIdentifiers() Control Identifiers: TkTopLevel - 'HD Die Tester' (L337, T254, R757, B735) ['HD Die TesterTkTopLevel', 'HD Die Tester', 'TkTopLevel'] child_window(title="HD Die Tester", class_name="TkTopLevel") | | TkChild - '' (L345, T305, R749, B727) | ['TkChild', 'HD Die TesterTkChild', 'TkChild0', 'TkChild1', 'HD Die TesterTkChild0', 'HD Die TesterTkChild1'] | child_window(class_name="TkChild") | | | | Static - '' (L345, T706, R749, B727) | | ['Static', 'HD Die TesterStatic', 'Static0', 'Static1', 'HD Die TesterStatic0', 'HD Die TesterStatic1'] | | child_window(class_name="Static") | | | | Static - '' (L544, T645, R550, B666) | | ['Static2', 'HD Die TesterStatic2'] | | child_window(class_name="Static") | | | | Button - '' (L345, T619, R749, B645) | | ['Button', 'HD Die TesterButton', 'Button0', 'Button1', 'HD Die TesterButton0', 'HD Die TesterButton1'] | | child_window(class_name="Button") | | | | TkChild - '' (L345, T687, R749, B706) | | ['TkChild2', 'HD Die TesterTkChild2'] | | child_window(class_name="TkChild") | | | | Static - '' (L345, T666, R546, B687) | | ['Static3', 'HD Die TesterStatic3'] | | child_window(class_name="Static") | | | | TkChild - '' (L418, T599, R749, B618) | | ['TkChild3', 'HD Die TesterTkChild3'] | | child_window(class_name="TkChild") | | | | TkChild - '' (L418, T578, R749, B597) | | ['TkChild4', 'HD Die TesterTkChild4'] | | child_window(class_name="TkChild") | | | | TkChild - '' (L418, T557, R749, B576) | | ['TkChild5', 'HD Die TesterTkChild5'] | | child_window(class_name="TkChild") | | | | TkChild - '' (L418, T536, R749, B555) | | ['TkChild6', 'HD Die TesterTkChild6'] | | child_window(class_name="TkChild") | | | | Static - '' (L345, T598, R387, B619) | | ['Static4', 'HD Die TesterStatic4'] | | child_window(class_name="Static") | | | | Static - '' (L345, T577, R383, B598) | | ['Static5', 'HD Die TesterStatic5'] | | child_window(class_name="Static") | | | | Static - '' (L345, T556, R418, B577) | | ['Static6', 'HD Die TesterStatic6'] | | child_window(class_name="Static") | | | | Static - '' (L345, T535, R413, B556) | | ['Static7', 'HD Die TesterStatic7'] | | child_window(class_name="Static") | | | | TkChild - '' (L345, T523, R749, B525) | | ['TkChild7', 'HD Die TesterTkChild7'] | | child_window(class_name="TkChild") | | | | Button - '' (L345, T487, R749, B513) | | ['Button2', 'HD Die TesterButton2'] | | child_window(class_name="Button") | | | | Button - '' (L345, T461, R749, B487) | | ['Button3', 'HD Die TesterButton3'] | | child_window(class_name="Button") | | | | TkChild - '' (L418, T441, R749, B460) | | ['TkChild8', 'HD Die TesterTkChild8'] | | child_window(class_name="TkChild") | | | | TkChild - '' (L418, T420, R749, B439) | | ['TkChild9', 'HD Die TesterTkChild9'] | | child_window(class_name="TkChild") | | | | Static - '' (L345, T440, R408, B461) | | ['Static8', 'HD Die TesterStatic8'] | | child_window(class_name="Static") | | | | Static - '' (L345, T419, R401, B440) | | ['Static9', 'HD Die TesterStatic9'] | | child_window(class_name="Static") | | | | Button - '' (L692, T394, R749, B419) | | ['Button4', 'HD Die TesterButton4'] | | child_window(class_name="Button") | | | | Button - '' (L527, T394, R582, B419) | | ['Button5', 'HD Die TesterButton5'] | | child_window(class_name="Button") | | | | Button - '' (L358, T394, R404, B419) | | ['Button6', 'HD Die TesterButton6'] | | child_window(class_name="Button") | | | | Static - '' (L345, T305, R749, B326) | | ['Static10', 'HD Die TesterStatic10'] | | child_window(class_name="Static") | | | | Static - '' (L345, T373, R749, B394) | | ['Static11', 'HD Die TesterStatic11'] | | child_window(class_name="Static") | | | | Static - '' (L345, T352, R749, B373) | | ['Static12', 'HD Die TesterStatic12'] | | child_window(class_name="Static") | | | | Button - '' (L345, T326, R749, B352) | | ['Button7', 'HD Die TesterButton7'] | | child_window(class_name="Button") | | | | TkChild - '' (L345, T305, R346, B306) | | ['TkChild10', 'HD Die TesterTkChild10'] | | child_window(class_name="TkChild") | | Static - '' (L345, T706, R749, B727) | ['Static', 'HD Die TesterStatic', 'Static0', 'Static1', 'HD Die TesterStatic0', 'HD Die TesterStatic1'] | child_window(class_name="Static") | | Static - '' (L544, T645, R550, B666) | ['Static2', 'HD Die TesterStatic2'] | child_window(class_name="Static") | | Button - '' (L345, T619, R749, B645) | ['Button', 'HD Die TesterButton', 'Button0', 'Button1', 'HD Die TesterButton0', 'HD Die TesterButton1'] | child_window(class_name="Button") | | TkChild - '' (L345, T687, R749, B706) | ['TkChild2', 'HD Die TesterTkChild2'] | child_window(class_name="TkChild") | | Static - '' (L345, T666, R546, B687) | ['Static3', 'HD Die TesterStatic3'] | child_window(class_name="Static") | | TkChild - '' (L418, T599, R749, B618) | ['TkChild3', 'HD Die TesterTkChild3'] | child_window(class_name="TkChild") | | TkChild - '' (L418, T578, R749, B597) | ['TkChild4', 'HD Die TesterTkChild4'] | child_window(class_name="TkChild") | | TkChild - '' (L418, T557, R749, B576) | ['TkChild5', 'HD Die TesterTkChild5'] | child_window(class_name="TkChild") | | TkChild - '' (L418, T536, R749, B555) | ['TkChild6', 'HD Die TesterTkChild6'] | child_window(class_name="TkChild") | | Static - '' (L345, T598, R387, B619) | ['Static4', 'HD Die TesterStatic4'] | child_window(class_name="Static") | | Static - '' (L345, T577, R383, B598) | ['Static5', 'HD Die TesterStatic5'] | child_window(class_name="Static") | | Static - '' (L345, T556, R418, B577) | ['Static6', 'HD Die TesterStatic6'] | child_window(class_name="Static") | | Static - '' (L345, T535, R413, B556) | ['Static7', 'HD Die TesterStatic7'] | child_window(class_name="Static") | | TkChild - '' (L345, T523, R749, B525) | ['TkChild7', 'HD Die TesterTkChild7'] | child_window(class_name="TkChild") | | Button - '' (L345, T487, R749, B513) | ['Button2', 'HD Die TesterButton2'] | child_window(class_name="Button") | | Button - '' (L345, T461, R749, B487) | ['Button3', 'HD Die TesterButton3'] | child_window(class_name="Button") | | TkChild - '' (L418, T441, R749, B460) | ['TkChild8', 'HD Die TesterTkChild8'] | child_window(class_name="TkChild") | | TkChild - '' (L418, T420, R749, B439) | ['TkChild9', 'HD Die TesterTkChild9'] | child_window(class_name="TkChild") | | Static - '' (L345, T440, R408, B461) | ['Static8', 'HD Die TesterStatic8'] | child_window(class_name="Static") | | Static - '' (L345, T419, R401, B440) | ['Static9', 'HD Die TesterStatic9'] | child_window(class_name="Static") | | Button - '' (L692, T394, R749, B419) | ['Button4', 'HD Die TesterButton4'] | child_window(class_name="Button") | | Button - '' (L527, T394, R582, B419) | ['Button5', 'HD Die TesterButton5'] | child_window(class_name="Button") | | Button - '' (L358, T394, R404, B419) | ['Button6', 'HD Die TesterButton6'] | child_window(class_name="Button") | | Static - '' (L345, T305, R749, B326) | ['Static10', 'HD Die TesterStatic10'] | child_window(class_name="Static") | | Static - '' (L345, T373, R749, B394) | ['Static11', 'HD Die TesterStatic11'] | child_window(class_name="Static") | | Static - '' (L345, T352, R749, B373) | ['Static12', 'HD Die TesterStatic12'] | child_window(class_name="Static") | | Button - '' (L345, T326, R749, B352) | ['Button7', 'HD Die TesterButton7'] | child_window(class_name="Button") | | TkChild - '' (L345, T305, R346, B306) | ['TkChild10', 'HD Die TesterTkChild10'] | child_window(class_name="TkChild")

请告知。你知道吗

以下是我的调试工作:

<强>1。通过编程查找文本框区域:

import pywinauto from pywinauto.application import Application app = Application().connect(title='HD Die Tester') app['HD Die Tester']['TkChild9'].draw_outline(colour='green', thickness=2)
这就是我看到的。

enter image description here

<强>2。使用“设置文本”在文本框中输入字符

app['HD Die Tester']['TkChild9'].set_text("hello")

出现错误消息

Traceback (most recent call last): File "<pyshell#8>", line 1, in <module> app['HD Die Tester']['TkChild9'].set_text("hello") File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\site-packages\pywinauto\application.py", line 182, in __call__ format(self.criteria[-1]['best_match'])) AttributeError: Neither GUI element (wrapper) nor wrapper method 'set_text' were found (typo?)

3岁。使用“设置键盘焦点”

app['HD Die Tester']['TkChild9'].set_keyboard_focus().type_keys("hello", set_foreground=False)

这是输出:

<hwndwrapper.HwndWrapper - '', TkChild, 2427666> hello

Gui上没有出现任何问题

enter image description here


Tags: namechildappstaticbuttonwindowclasstester
1条回答
网友
1楼 · 发布于 2024-10-02 16:21:20

.click_input()方法将有助于在键入之前正确设置输入焦点。而且.wrapper_object()显然返回HwndWrapper而不是EditWrapper,因此这意味着该元素未被检测为编辑框。它可以显式转换为EditWrapper对象。为此目的使用此导入:

from pywinauto.controls.win32_controls import EditWrapper

edit = EditWrapper(app['HD Die Tester']['TkChild9'].wrapper_object())
edit.set_edit_text("hello") # or try type_keys(...)

相关问题 更多 >