#pywinauto
Вопрос:
Я пытаюсь автоматизировать тест входа в приложение Windows для обнаружения проблем с подключением.
Когда попытка входа в систему завершается неудачно, приложение возвращает всплывающее окно. Мой скрипт (см. Ниже) продолжит работу в блоке «попробовать» только после того, как я нажму кнопку » ОК » во всплывающем окне.
Мой план состоит в том, чтобы получить сообщение об ошибке во всплывающем окне и отправить предупреждение по электронной почте.
Был бы признателен за несколько советов. Я совершенно новичок в pywinauto и ничего не нашел в документации.
Большое спасибо.
Сценарий:
from pywinauto import application
import time
app = application.Application(backend="uia")
app.start(r"C:Program Files (x86)xxxMedxxxc.exe", wait_for_idle=False)
main_win = app.window(title='Medxxxc')
#main_win_wrapper = main_win.set_focus()
#sign_in = main_win.child_window(title="Sign in", depth=2)
#sign_in = main_win.child_window(title="Connect to a Database", auto_id="DBConnect", control_type="Window")
sign_in = main_win.child_window(title="Connect to a Database", depth=3)
cnxnstring = sign_in.child_window(title="Connection:", auto_id="cboConnections", control_type="ComboBox")
username = sign_in.child_window(title="User Name:", auto_id="txtUserName", control_type="Edit")
password = sign_in.child_window(title="Password:", auto_id="txtPassword", control_type="Edit")
connect = sign_in.child_window(title="Connect", auto_id="cmdConnect", control_type="Button")
cnxnstring.select("Rexxxing")
username.iface_value.SetValue("myusername")
password.iface_value.SetValue("dummypasswd")
connect.click()
try:
sign_in_error = main_win.child_window(title="OK", depth=4)
print("sign-in error")
sign_in_error.print_control_identifiers()
except Exception as e:
print("%s" % e)
Вот что я вижу в командной строке после нажатия кнопки » ОК » во всплывающем окне:
(venv32) c:venv32Scripts>python c:testcheck_myapp.py
sign-in error
{'title': 'OK', 'depth': 4, 'top_level_only': False, 'parent': <uia_element_info.UIAElementInfo - 'MediTxxc', WindowsForms10.Window.8.app.0.1517e87_r9_ad1, 332134>, 'backend': 'uia'}
Вот всплывающее окно msg с ошибкой, на которое я пытаюсь сфокусироваться:
И вот верхняя часть идентификаторов:
Control Identifiers:
Dialog - 'MediTxxc' (L408, T141, R1353, B775)
['MediTxxc', 'MediTxxcDialog', 'Dialog', 'Dialog0', 'Dialog1']
child_window(title="MediTxxc", auto_id="MDIForm", control_type="Window")
|
| Dialog - 'Connect to a Database' (L666, T366, R1095, B549)
| ['Connect to a DatabaseDialog', 'Connect to a Database', 'Dialog2']
| child_window(title="Connect to a Database", auto_id="DBConnect", control_type="Window")
| |
| | Dialog - 'MediTxxc' (L830, T471, R1106, B630)
| | ['MediTxxcDialog', 'MediTxxc', 'Dialog3']
| | child_window(title="MediTxxc", control_type="Window")
| | |
| | | Button - 'OK' (L1008, T590, R1083, B613)
| | | ['Button', 'OKButton', 'OK', 'Button0', 'Button1']
| | | child_window(title="OK", auto_id="2", control_type="Button")
| | |
| | | Image - '' (L859, T525, R891, B557)
| | | ['Image', 'Password:Image']
| | | child_window(auto_id="20", control_type="Image")
| | |
| | | Static - 'Login failed for user 'sxxxxxxa'.' (L900, T535, R1068, B550)
| | | ['Static', "Login failed for user 'sxxxxxxa'.Static", "Login failed for user 'sxxxxxxa'.", 'Static0', 'Static1']
| | | child_window(title="Login failed for user 'sxxxxxxa'.", auto_id="65535", control_type="Text")
| | |
| | | TitleBar - '' (L838, T474, R1098, B502)
| | | ['TitleBar', 'User Name:TitleBar', 'TitleBar0', 'TitleBar1']
| | | |
| | | | Button - 'Close' (L1065, T472, R1099, B502)
| | | | ['Close', 'CloseButton', 'Button2', 'Close0', 'Close1', 'CloseButton0', 'CloseButton1']
| | | | child_window(title="Close", control_type="Button")
| |
| | GroupBox - 'Connection Information' (L688, T411, R1073, B527)
| | ['Connection InformationGroupBox', 'GroupBox', 'Connection Information']
| | child_window(title="Connection Information", auto_id="frmConInfo", control_type="Group")
| | |
| | | Edit - 'User Name:' (L787, T465, R962, B485)
| | | ['User Name:Edit', 'Edit', 'Edit0', 'Edit1']
| | | child_window(title="User Name:", auto_id="txtUserName", control_type="Edit")
| | |
| | | Button - 'Cancel' (L979, T463, R1064, B488)
| | | ['CancelButton', 'Button3', 'Cancel']
| | | child_window(title="Cancel", auto_id="cmdCancel", control_type="Button")
| | |
| | | Edit - 'Password:' (L787, T495, R962, B515)
| | | ['Edit2', 'Password:Edit']
| | | child_window(title="Password:", auto_id="txtPassword", control_type="Edit")
| | |
| | | Button - 'Connect' (L979, T430, R1064, B455)
| | | ['Button4', 'ConnectButton', 'Connect']
| | | child_window(title="Connect", auto_id="cmdConnect", control_type="Button")
| | |
| | | ComboBox - 'Connection:' (L787, T430, R962, B452)
| | | ['Connection:ComboBox', 'Connection:', 'ComboBox', 'Connection:0', 'Connection:1']
| | | child_window(title="Connection:", auto_id="cboConnections", control_type="ComboBox")
| | | |
| | | | Static - 'Connection:' (L3, T3, R155, B19)
| | | | ['Static2', 'Connection:2', 'Connection:Static', 'Connection:Static0', 'Connection:Static1']
| | | | child_window(title="Connection:", control_type="Text")
| | | |
| | | | Button - 'Open' (L946, T431, R961, B451)
| | | | ['OpenButton', 'Button5', 'Open']
| | | | child_window(title="Open", control_type="Button")
| | |
| | | Static - 'User Name:' (L711, T468, R781, B482)
| | | ['User Name:Static', 'Static3', 'User Name:']
| | | child_window(title="User Name:", auto_id="lblUserName", control_type="Text")
| | |
| | | Static - 'Password:' (L715, T498, R781, B512)
| | | ['Static4', 'Password:Static', 'Password:', 'Password:Static0', 'Password:Static1']
| | | child_window(title="Password:", auto_id="lblPassword", control_type="Text")
| | |
| | | Static - 'Connection:' (L708, T438, R781, B452)
| | | ['Static5', 'Connection:3', 'Connection:Static2']
| | | child_window(title="Connection:", auto_id="lblServer", control_type="Text")
И
Ответ №1:
Разобрался в проблеме. Я изменил эту строку
connect.click()
Для
connect.click_input()
Теперь скрипт переходит к кнопке OK во всплывающем окне.
Спасибо.