Получить текст из элемента управления wxWindow с помощью pywinauto - PullRequest
1 голос
/ 05 апреля 2019

Я использую pywinauto версию 0.6.6 для управления FMSLogo приложением.Я не могу получить доступ к тексту из элемента управления wxWindow в приложении FMSLogo.Методы .texts() и .window_text() возвращают 'text', который не является текстовым содержимым элемента управления.Вот мой код:

from pywinauto.application import Application
app = Application().start(r"C:/app/dev/FMSLogo/FMSLogo.exe")
dlg = app.top_window()
dlg.text.DrawOutline("red")
dlg.text.texts()
# ['text']
dlg.child_window(title="text", class_name="wxWindow").texts()
# ['text']

Это вывод dlg.print_control_identifiers()

Control Identifiers:

wxWindowNR - 'FMSLogo'    (L108, T3, R1082, B771)
['wxWindowNR', 'FMSLogowxWindowNR', 'FMSLogo', 'wxWindowNR0', 'wxWindowNR1']
child_window(title="FMSLogo", class_name="wxWindowNR")
   | 
   | wxWindowNR - 'splitter'    (L116, T54, R1074, B763)
   | ['wxWindowNR2', 'splitterwxWindowNR', 'splitter']
   | child_window(title="splitter", class_name="wxWindowNR")
   |    | 
   |    | wxWindowNR - 'panel'    (L118, T56, R1072, B166)
   |    | ['wxWindowNR3', 'panel', 'panelwxWindowNR', 'panel0', 'panel1', 'panelwxWindowNR0', 'panelwxWindowNR1']
   |    | child_window(title="panel", class_name="wxWindowNR")
   |    | 
   |    | wxWindowNR - 'panel'    (L118, T173, R1072, B761)
   |    | ['wxWindowNR4', 'panel2', 'panelwxWindowNR2']
   |    | child_window(title="panel", class_name="wxWindowNR")
   |    |    | 
   |    |    | wxWindow - 'text'    (L122, T173, R910, B733)
   |    |    | ['wxWindow', 'textwxWindow', 'text']
   |    |    | child_window(title="text", class_name="wxWindow")
   |    |    | 
   |    |    | wxWindowNR - 'stcwindow'    (L122, T735, R910, B757)
   |    |    | ['wxWindowNR5', 'stcwindow', 'stcwindowwxWindowNR']
   |    |    | child_window(title="stcwindow", class_name="wxWindowNR")
   |    |    | 
   |    |    | Button - 'Zaustavi'    (L912, T177, R990, B202)
   |    |    | ['Zaustavi', 'ZaustaviButton', 'Button', 'Button0', 'Button1']
   |    |    | child_window(title="Zaustavi", class_name="Button")
   |    |    | 
   |    |    | Button - 'Trace'    (L990, T177, R1068, B202)
   |    |    | ['Button2', 'TraceButton', 'Trace']
   |    |    | child_window(title="Trace", class_name="Button")
   |    |    | 
   |    |    | Button - 'Pauziraj'    (L912, T202, R990, B227)
   |    |    | ['PauzirajButton', 'Button3', 'Pauziraj']
   |    |    | child_window(title="Pauziraj", class_name="Button")
   |    |    | 
   |    |    | Button - 'Stanje'    (L990, T202, R1068, B227)
   |    |    | ['Stanje', 'Button4', 'StanjeButton']
   |    |    | child_window(title="Stanje", class_name="Button")
   |    |    | 
   |    |    | Button - 'Step'    (L912, T227, R990, B252)
   |    |    | ['Step', 'Button5', 'StepButton']
   |    |    | child_window(title="Step", class_name="Button")
   |    |    | 
   |    |    | Button - 'Ispočetka'    (L990, T227, R1068, B252)
   |    |    | ['Button6', 'IspočetkaButton', 'Ispočetka']
   |    |    | child_window(title="Ispočetka", class_name="Button")
   |    |    | 
   |    |    | Button - 'Izvrši'    (L912, T732, R990, B757)
   |    |    | ['Button7', 'Izvrši', 'IzvršiButton']
   |    |    | child_window(title="Izvrši", class_name="Button")
   |    |    | 
   |    |    | Button - 'Uredi sve'    (L990, T732, R1068, B757)
   |    |    | ['Button8', 'Uredi sveButton', 'Uredi sve']
   |    |    | child_window(title="Uredi sve", class_name="Button")
   |    | 
   |    | wxWindow - 'text'    (L122, T173, R910, B733)
   |    | ['wxWindow', 'textwxWindow', 'text']
   |    | child_window(title="text", class_name="wxWindow")
   |    | 
   |    | wxWindowNR - 'stcwindow'    (L122, T735, R910, B757)
   |    | ['wxWindowNR5', 'stcwindow', 'stcwindowwxWindowNR']
   |    | child_window(title="stcwindow", class_name="wxWindowNR")
   |    | 
   |    | Button - 'Zaustavi'    (L912, T177, R990, B202)
   |    | ['Zaustavi', 'ZaustaviButton', 'Button', 'Button0', 'Button1']
   |    | child_window(title="Zaustavi", class_name="Button")
   |    | 
   |    | Button - 'Trace'    (L990, T177, R1068, B202)
   |    | ['Button2', 'TraceButton', 'Trace']
   |    | child_window(title="Trace", class_name="Button")
   |    | 
   |    | Button - 'Pauziraj'    (L912, T202, R990, B227)
   |    | ['PauzirajButton', 'Button3', 'Pauziraj']
   |    | child_window(title="Pauziraj", class_name="Button")
   |    | 
   |    | Button - 'Stanje'    (L990, T202, R1068, B227)
   |    | ['Stanje', 'Button4', 'StanjeButton']
   |    | child_window(title="Stanje", class_name="Button")
   |    | 
   |    | Button - 'Step'    (L912, T227, R990, B252)
   |    | ['Step', 'Button5', 'StepButton']
   |    | child_window(title="Step", class_name="Button")
   |    | 
   |    | Button - 'Ispočetka'    (L990, T227, R1068, B252)
   |    | ['Button6', 'IspočetkaButton', 'Ispočetka']
   |    | child_window(title="Ispočetka", class_name="Button")
   |    | 
   |    | Button - 'Izvrši'    (L912, T732, R990, B757)
   |    | ['Button7', 'Izvrši', 'IzvršiButton']
   |    | child_window(title="Izvrši", class_name="Button")
   |    | 
   |    | Button - 'Uredi sve'    (L990, T732, R1068, B757)
   |    | ['Button8', 'Uredi sveButton', 'Uredi sve']
   |    | child_window(title="Uredi sve", class_name="Button")
   | 
   | wxWindowNR - 'panel'    (L118, T56, R1072, B166)
   | ['wxWindowNR3', 'panel', 'panelwxWindowNR', 'panel0', 'panel1', 'panelwxWindowNR0', 'panelwxWindowNR1']
   | child_window(title="panel", class_name="wxWindowNR")
   | 
   | wxWindowNR - 'panel'    (L118, T173, R1072, B761)
   | ['wxWindowNR4', 'panel2', 'panelwxWindowNR2']
   | child_window(title="panel", class_name="wxWindowNR")
   |    | 
   |    | wxWindow - 'text'    (L122, T173, R910, B733)
   |    | ['wxWindow', 'textwxWindow', 'text']
   |    | child_window(title="text", class_name="wxWindow")
   |    | 
   |    | wxWindowNR - 'stcwindow'    (L122, T735, R910, B757)
   |    | ['wxWindowNR5', 'stcwindow', 'stcwindowwxWindowNR']
   |    | child_window(title="stcwindow", class_name="wxWindowNR")
   |    | 
   |    | Button - 'Zaustavi'    (L912, T177, R990, B202)
   |    | ['Zaustavi', 'ZaustaviButton', 'Button', 'Button0', 'Button1']
   |    | child_window(title="Zaustavi", class_name="Button")
   |    | 
   |    | Button - 'Trace'    (L990, T177, R1068, B202)
   |    | ['Button2', 'TraceButton', 'Trace']
   |    | child_window(title="Trace", class_name="Button")
   |    | 
   |    | Button - 'Pauziraj'    (L912, T202, R990, B227)
   |    | ['PauzirajButton', 'Button3', 'Pauziraj']
   |    | child_window(title="Pauziraj", class_name="Button")
   |    | 
   |    | Button - 'Stanje'    (L990, T202, R1068, B227)
   |    | ['Stanje', 'Button4', 'StanjeButton']
   |    | child_window(title="Stanje", class_name="Button")
   |    | 
   |    | Button - 'Step'    (L912, T227, R990, B252)
   |    | ['Step', 'Button5', 'StepButton']
   |    | child_window(title="Step", class_name="Button")
   |    | 
   |    | Button - 'Ispočetka'    (L990, T227, R1068, B252)
   |    | ['Button6', 'IspočetkaButton', 'Ispočetka']
   |    | child_window(title="Ispočetka", class_name="Button")
   |    | 
   |    | Button - 'Izvrši'    (L912, T732, R990, B757)
   |    | ['Button7', 'Izvrši', 'IzvršiButton']
   |    | child_window(title="Izvrši", class_name="Button")
   |    | 
   |    | Button - 'Uredi sve'    (L990, T732, R1068, B757)
   |    | ['Button8', 'Uredi sveButton', 'Uredi sve']
   |    | child_window(title="Uredi sve", class_name="Button")
   | 
   | wxWindow - 'text'    (L122, T173, R910, B733)
   | ['wxWindow', 'textwxWindow', 'text']
   | child_window(title="text", class_name="wxWindow")
   | 
   | wxWindowNR - 'stcwindow'    (L122, T735, R910, B757)
   | ['wxWindowNR5', 'stcwindow', 'stcwindowwxWindowNR']
   | child_window(title="stcwindow", class_name="wxWindowNR")
   | 
   | Button - 'Zaustavi'    (L912, T177, R990, B202)
   | ['Zaustavi', 'ZaustaviButton', 'Button', 'Button0', 'Button1']
   | child_window(title="Zaustavi", class_name="Button")
   | 
   | Button - 'Trace'    (L990, T177, R1068, B202)
   | ['Button2', 'TraceButton', 'Trace']
   | child_window(title="Trace", class_name="Button")
   | 
   | Button - 'Pauziraj'    (L912, T202, R990, B227)
   | ['PauzirajButton', 'Button3', 'Pauziraj']
   | child_window(title="Pauziraj", class_name="Button")
   | 
   | Button - 'Stanje'    (L990, T202, R1068, B227)
   | ['Stanje', 'Button4', 'StanjeButton']
   | child_window(title="Stanje", class_name="Button")
   | 
   | Button - 'Step'    (L912, T227, R990, B252)
   | ['Step', 'Button5', 'StepButton']
   | child_window(title="Step", class_name="Button")
   | 
   | Button - 'Ispočetka'    (L990, T227, R1068, B252)
   | ['Button6', 'IspočetkaButton', 'Ispočetka']
   | child_window(title="Ispočetka", class_name="Button")
   | 
   | Button - 'Izvrši'    (L912, T732, R990, B757)
   | ['Button7', 'Izvrši', 'IzvršiButton']
   | child_window(title="Izvrši", class_name="Button")
   | 
   | Button - 'Uredi sve'    (L990, T732, R1068, B757)
   | ['Button8', 'Uredi sveButton', 'Uredi sve']
   | child_window(title="Uredi sve", class_name="Button")

Inspect.exe в режиме MSAA дает это для элемента управления.

How found:  Focus [o:0xFFFFFFFFFFFFFFFC,c:0x0]
    hwnd=0x0000000000040220 32bit class="wxWindow" style=0x52010000 ex=0x0
ChildId:    0
Interfaces: IEnumVARIANT IOleWindow IAccIdentity
Impl:   Local oleacc proxy
AnnotationID:   0100008020020400FCFFFFFF00000000
Name:   "text"
Value:  [null]
Role:   client (0xA)
State:  focused,focusable (0x100004)
Location:   {l:-1911, t:701, w:784, h:306}
Selection:  
Description:    [null]
Kbshortcut: [null]
DefAction:  [null]
Help:   [null]
HelpTopic:  ""
ChildCount: 0
Window: 0x40220
FirstChild: [null]
LastChild:  [null]
Next:   [null]
Previous:   [null]
Left:   [null]
Up: [null]
Right:  [null]
Down:   [null]
Other Props:    Object has no additional properties
Children:   Container has no children
Ancestors:  "text" : window : focused,focusable
    "panel" : client : focusable
    "panel" : window : focusable
    "splitter" : client : focusable
    "splitter" : window : focusable
    "FMSLogo" : client : focusable
    "FMSLogo" : window : sizeable,moveable,focusable
    "Desktop 1" : client : focusable
    "Desktop 1" : window : focusable
    [ No Parent ]

Inspect.exe в режиме автоматизации пользовательского интерфейса дает это для управления.

How found:  Focus
    hwnd=0x0000000000040220 32bit class="wxWindow" style=0x52010000 ex=0x0
Name:   "text"
ControlType:    UIA_PaneControlTypeId (0xC371)
LocalizedControlType:   "pane"
BoundingRectangle:  {l:-1913 t:699 r:-1125 b:1009}
IsEnabled:  true
IsOffscreen:    false
IsKeyboardFocusable:    true
HasKeyboardFocus:   true
AccessKey:  ""
ProcessId:  8036
RuntimeId:  [2A.40220]
AutomationId:   "6008"
FrameworkId:    "Win32"
ClassName:  "wxWindow"
NativeWindowHandle: 0x40220
ProviderDescription:    "[pid:4384,providerId:0x40220 Main:Nested [pid:8036,providerId:0x40220 Annotation(parent link):Microsoft: Annotation Proxy (unmanaged:uiautomationcore.dll); Main:Microsoft: MSAA Proxy (unmanaged:uiautomationcore.dll)]; Nonclient:Microsoft: Non-Client Proxy (unmanaged:uiautomationcore.dll); Hwnd(parent link):Microsoft: HWND Proxy (unmanaged:uiautomationcore.dll)]"
IsPassword: false
HelpText:   ""
IsDialog:   [Not supported]
LegacyIAccessible.ChildId:  0
LegacyIAccessible.DefaultAction:    ""
LegacyIAccessible.Description:  ""
LegacyIAccessible.Help: ""
LegacyIAccessible.KeyboardShortcut: ""
LegacyIAccessible.Name: "text"
LegacyIAccessible.Role: client (0xA)
LegacyIAccessible.State:    focused,focusable (0x100004)
LegacyIAccessible.Value:    ""
IsAnnotationPatternAvailable:   false
IsDragPatternAvailable: false
IsDockPatternAvailable: false
IsDropTargetPatternAvailable:   false
IsExpandCollapsePatternAvailable:   false
IsGridItemPatternAvailable: false
IsGridPatternAvailable: false
IsInvokePatternAvailable:   false
IsItemContainerPatternAvailable:    false
IsLegacyIAccessiblePatternAvailable:    true
IsMultipleViewPatternAvailable: false
IsObjectModelPatternAvailable:  false
IsRangeValuePatternAvailable:   false
IsScrollItemPatternAvailable:   false
IsScrollPatternAvailable:   false
IsSelectionItemPatternAvailable:    false
IsSelectionPatternAvailable:    false
IsSpreadsheetItemPatternAvailable:  false
IsSpreadsheetPatternAvailable:  false
IsStylesPatternAvailable:   false
IsSynchronizedInputPatternAvailable:    false
IsTableItemPatternAvailable:    false
IsTablePatternAvailable:    false
IsTextChildPatternAvailable:    false
IsTextEditPatternAvailable: false
IsTextPatternAvailable: false
IsTextPattern2Available:    false
IsTogglePatternAvailable:   false
IsTransformPatternAvailable:    false
IsTransform2PatternAvailable:   false
IsValuePatternAvailable:    false
IsVirtualizedItemPatternAvailable:  false
IsWindowPatternAvailable:   false
IsCustomNavigationPatternAvailable: false
IsSelectionPattern2Available:   false
FirstChild: [null]
LastChild:  [null]
Next:   "stcwindow" pane
Previous:   [null]
Other Props:    Object has no additional properties
Children:   Container has no children
Ancestors:  "panel" pane
    "splitter" pane
    "FMSLogo" window
    "Desktop 1" pane
    [ No Parent ]

1 Ответ

0 голосов
/ 05 апреля 2019

не могли бы вы попробовать метод window_text ()?

...