PywinautoHow to get message contents from dialog box(如何从对话框获取消息内容)

2024-05-05 02:58:48 发布

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

我用VB完成了表格。例如,单击“提交”按钮后会出现警报框,我想读取警报框中的静态内容。这是我的代码:

    import sys
    import json
    from pywinauto.application import Application
    print("test")
    app = Application(backend="uia").start("")
    data=json.loads(sys.argv[1])
    text=[]
    for rec in data:
        app.Form1.Edit6.type_keys(rec['name'])
        app.Form1.Edit5.type_keys(rec['age'])
        if rec['gender']=="male":
           app.Form1.Male.click()
        elif rec['gender']=="female":
           app.Form1.Female.click()

    app.Form1.Edit3.type_keys(rec['phnum'])

    app.Form1.Submit.click_input()

   app.Form1.Success.wait('visible', timeout=20)
   text=app.Form1.Success.Static.WindowText()

   app.Form1.Success.OKButton.click_input() 

  print("Records Submitted for ",rec['name'])
  print('\n')
  app.Form1.close()
  print text
 sys.stdout.flush()

Tags: textimportjsonappdataapplicationtypesys