首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF窗格-使用PyWinAuto读取文本

WPF窗格-使用PyWinAuto读取文本
EN

Stack Overflow用户
提问于 2020-06-10 19:49:14
回答 4查看 1.1K关注 0票数 0

我正在尝试从WPF窗格窗口中读取文本。以前这个窗口是一个普通的win32窗口。所以我的自动化脚本运行得很好。现在,由于开发人员已将其更改为WPF;Swapy.exe无法检测到它。因此,我尝试了UIA方法并使用Inspect.exe。

我面临的挑战是如何结合使用Inspect.exe和pywinauto来读取文本数据。

有没有办法从WPF窗格窗口中读取文本?

这里我正在复制从Inspect.exe获得的窗格窗口详细信息

代码语言:javascript
复制
    How found:  Focus
    Name:   ""
    ControlType:    UIA_PaneControlTypeId (0xC371)
    LocalizedControlType:   "pane"
    BoundingRectangle:  {l:639 t:541 r:1337 b:657}
    IsEnabled:  true
    IsOffscreen:    false
    IsKeyboardFocusable:    true
    HasKeyboardFocus:   true
    AcceleratorKey: ""
    AccessKey:  ""
    ProcessId:  17928
    RuntimeId:  [7.4608.364D350]
    AutomationId:   ""
    FrameworkId:    "WPF"
    ClassName:  "ScrollViewer"
    IsControlElement:   true
    IsContentElement:   true
    ProviderDescription:    "[pid:17928,providerId:0x0 Main(parent link):Unidentified Provider (managed:MS.Internal.Automation.ElementProxy, PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)]"
    IsPassword: false
    ItemStatus: ""
    ItemType:   ""
    IsRequiredForForm:  false
    HelpText:   ""
    ClickablePoint: {x:988 y:599}
    Orientation:    0
    LegacyIAccessible.ChildId:  0
    LegacyIAccessible.DefaultAction:    ""
    LegacyIAccessible.Description:  ""
    LegacyIAccessible.Help: ""
    LegacyIAccessible.KeyboardShortcut: ""
    LegacyIAccessible.Name: ""
    LegacyIAccessible.Role: pane (0x10)
    LegacyIAccessible.State:    focused,focusable (0x100004)
    LegacyIAccessible.Value:    ""
    Scroll.HorizontallyScrollable:  false
    Scroll.HorizontalScrollPercent: -1.000000
    Scroll.HorizontalViewSize:  100.000000
    Scroll.VerticallyScrollable:    false
    Scroll.VerticalScrollPercent:   -1.000000
    Scroll.VerticalViewSize:    100.000000
    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:   true
    IsSelectionItemPatternAvailable:    false
    IsSelectionPatternAvailable:    false
    IsSpreadsheetItemPatternAvailable:  false
    IsSpreadsheetPatternAvailable:  false
    IsStylesPatternAvailable:   false
    IsSynchronizedInputPatternAvailable:    true
    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: "" text
    LastChild:  "" scroll bar
    Next:   [null]
    Previous:   [null]
    Other Props:    Object has no additional properties
    Children:   "" text
    "0x5107:031 Cycle length" text
    "Value:" text
    "14405 Unit" text
    "Factory setting:" text
    "360 Unit" text
    "Range:" text
    "0.000000001 ... 2147483647 Unit" text
    "Raw value:" text
    "14405 (0x000000008022CC40)" text
    "Data type:" text
    "LREAL - IEEE 754 Long Real (8 bytes)" text
    "Note:" text
    "PC must be inhibited before write operation!" text
    "" text
    "" scroll bar
    "" scroll bar
    Ancestors:  "" custom
    "" custom
    "elementHost" pane
    "elementHost" pane
    "" pane
    "Filter active!" pane
    "" pane
    "" pane
    "" pane
    "" pane
    "" pane
    "" pane
    "Parameter list" pane
    "" tab
    "" pane
    "" pane
    "Device" pane
    "" pane
    "UpdateMotionAxesABC_OldVersion.prj - My Applicaiton 3.21.0" window
    "Desktop 1" pane
    [ No Parent ]
EN

回答 4

Stack Overflow用户

发布于 2020-06-14 16:01:59

我能够读懂课文。请参见下面的代码片段

代码语言:javascript
复制
from pywinauto.application import Application
from pywinauto import application

plcPid = application.process_from_module(module = 'MyApp.exe')
wpfApp = Application(backend='uia').connect(process=plcPid)

handle = wpfApp.window_(title='MyDoc.project - MyApp 3.21.0')
child = handle.child_window(auto_id='elementHostInfoBox')

child0 = child.wrapper_object()

child1 = child0.children()
child2 = child1[0].children()
child3 = child2[0].children()
print(child3[0].children_texts())
票数 1
EN

Stack Overflow用户

发布于 2020-06-29 15:22:34

代码语言:javascript
复制
Hi Sachin,

Even i am facing a similar issue and not able to read the text present in the text box,

coping the pane window details which I got from Inspect.exe

How found:  Mouse move (481,182)
    hwnd=0x00060E74 32bit class="HwndWrapper[IKEA.Mfs.Sales.App.iSell.exe;;983a900c-7814-40e2-a87e-ab06b28a7dd5]" style=0x56010000 RuntimeId:   "[7.12692.48621330]"
BoundingRectangle:  {l:470 t:174 r:666 b:194}
ProcessId:  12692
ControlType:    UIA_EditControlTypeId (0xC354)
LocalizedControlType:   "edit"
Name:   ""
AcceleratorKey: ""
AccessKey:  ""
HasKeyboardFocus:   true
IsKeyboardFocusable:    true
IsEnabled:  true
AutomationId:   "TextboxContactMethodEmailData"
ClassName:  "TextBox"
HelpText:   ""
ClickablePoint: {x:568 y:184}
IsControlElement:   true
IsContentElement:   true
IsPassword: false
ItemType:   ""
IsOffscreen:    false
Orientation:    0
FrameworkId:    "WPF"
IsRequiredForForm:  false
ItemStatus: ""
ProviderDescription:    "[pid:12692,providerId:0x0 Main(parent link):Unidentified Provider (managed:MS.Internal.Automation.ElementProxy, PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)]"
Value.IsReadOnly:   false
Value.Value:    "test@test.com"
Scroll.HorizontalScrollPercent: -1.000000
Scroll.HorizontalViewSize:  100.000000
Scroll.VerticalScrollPercent:   -1.000000
Scroll.VerticalViewSize:    100.000000
Scroll.HorizontallyScrollable:  false
Scroll.VerticallyScrollable:    false
IsDockPatternAvailable: false
IsExpandCollapsePatternAvailable:   false
IsGridItemPatternAvailable: false
IsGridPatternAvailable: false
IsInvokePatternAvailable:   false
IsMultipleViewPatternAvailable: false
IsRangeValuePatternAvailable:   false
IsScrollPatternAvailable:   true
IsScrollItemPatternAvailable:   false
IsSelectionItemPatternAvailable:    false
IsSelectionPatternAvailable:    false
IsTablePatternAvailable:    false
IsTableItemPatternAvailable:    false
IsTextPatternAvailable: true
IsTogglePatternAvailable:   false
IsTransformPatternAvailable:    false
IsValuePatternAvailable:    true
IsWindowPatternAvailable:   false
IsItemContainerPatternAvailable:    false
IsVirtualizedItemPatternAvailable:  false
FirstChild: "" pane
LastChild:  "" pane
Next:   "" radio button
Previous:   "Email" text
Other Props:    Object has no additional properties
Children:   "" pane
Ancestors:  "" custom
    "" custom
    "Preferred way of communication" group
    "" custom
    "Billing info" group
    "" pane
    "" custom
    "" custom
    "IcmCustomerHost" pane
    "IcmCustomerHost" pane
    "Customer Profile - Private" window
    "iSell (CTE-F2)2" window
    "Desktop 1" pane
    [ No Parent ]

Please do help me how can i read text inside a text box or set some value in text box,
票数 0
EN

Stack Overflow用户

发布于 2020-06-30 19:36:01

代码语言:javascript
复制
My application is not completely of wpf panes .  it has a win32 forms in the home page and when i click a button to create a customer it will be navigated to a window which id of wpf and there i am able to wrap only the title of the window and don't see any descendents like textboxes and buttons using swappy like below

def wpftesting():
        app=Application().connect(title=u'Customer Profile - Private', class_name='WindowsForms10.Window.8.app.0.21093c0_r30_ad1')               
        fC_window = app[u'Customer Profile - Private']
        fC_window.print_control_identifiers()

this is what i see only the title of the pane

Control Identifiers:

WindowsForms10.Window.8.app.0.21093c0_r30_ad1 - 'Customer Profile - Private'    (L341, T42, R1025, B686)
['WindowsForms10.Window.8.app.0.21093c0_r30_ad1', 'Customer Profile - PrivateWindowsForms10.Window.8.app.0.21093c0_r30_ad1', 'Customer Profile - Private', 'WindowsForms10.Window.8.app.0.21093c0_r30_ad10', 'WindowsForms10.Window.8.app.0.21093c0_r30_ad11']
child_window(title="Customer Profile - Private", auto_id="IcmCustomerUi", control_type="IKEA.Mfs.Icm.Uil.Icm.Ui.IcmCustomerUi")
   |
   | WindowsForms10.Window.8.app.0.21093c0_r30_ad1 - 'IcmCustomerHost'    (L349, T73, R1017, B656)
   | ['IcmCustomerHost', 'WindowsForms10.Window.8.app.0.21093c0_r30_ad12', 'IcmCustomerHostWindowsForms10.Window.8.app.0.21093c0_r30_ad1', 'IcmCustomerHost0', 'IcmCustomerHost1']
   | child_window(title="IcmCustomerHost", auto_id="IcmCustomerHost", control_type="System.Windows.Forms.Integration.ElementHost")
   |    |
   |    | HwndWrapper[IKEA.Mfs.Sales.App.iSell.exe;;c2aeda95-6754-42bc-9936-9f13c37a34df] - 'IcmCustomerHost'    (L349, T73, R1017, B656)
   |    | ['IcmCustomerHostHwndWrapper[IKEA.Mfs.Sales.App.iSell.exe;;c2aeda95-6754-42bc-9936-9f13c37a34df]', 'HwndWrapper[IKEA.Mfs.Sales.App.iSell.exe;;c2aeda95-6754-42bc-9936-9f13c37a34df]', 'IcmCustomerHost2']
   |    | child_window(title="IcmCustomerHost", class_name="HwndWrapper[IKEA.Mfs.Sales.App.iSell.exe;;c2aeda95-6754-42bc-9936-9f13c37a34df]")
   |
   | HwndWrapper[IKEA.Mfs.Sales.App.iSell.exe;;c2aeda95-6754-42bc-9936-9f13c37a34df] - 'IcmCustomerHost'    (L349, T73, R1017, B656)
   | ['IcmCustomerHostHwndWrapper[IKEA.Mfs.Sales.App.iSell.exe;;c2aeda95-6754-42bc-9936-9f13c37a34df]', 'HwndWrapper[IKEA.Mfs.Sales.App.iSell.exe;;c2aeda95-6754-42bc-9936-9f13c37a34df]', 'IcmCustomerHost2']
   | child_window(title="IcmCustomerHost", class_name="HwndWrapper[IKEA.Mfs.Sales.App.iSell.exe;;c2aeda95-6754-42bc-9936-9f13c37a34df]")
   |
   | StatusBar - ''    (L349, T656, R1017, B678)
   | ['Customer Profile - PrivateStatusBar', 'StatusBar']
   | child_window(auto_id="StatusBar1", control_type="IKEA.Mdif.Sys.Uil.MdifStatusBar")


. As mentioned to use  backend='uia' for wpf panes and it throws an error like below

def wpftesting():
        app=Application(backend='uia').connect(title=u'Customer Profile - Private', class_name='WindowsForms10.Window.8.app.0.21093c0_r30_ad1')               
        fC_window = app[u'Customer Profile - Private']
        fC_window.print_control_identifiers()

pywinauto.findwindows.ElementNotFoundError: {'title': 'Customer Profile - Private', 'class_name': 'WindowsForms10.Window.8.app.0.21093c0_r30_ad1', 'backend': 'uia', 'visible_only': False}




. No idea how to use this inspect.exe tool found properties in pywinauto. can you please post some sample code like def delivery_questionaries():
dQ = Application().connect(title=u'Delivery questions', class_name='WindowsForms10.Window.8.app.0.21093c0_r30_ad1')
        dQ_window = dQ[u'Delivery questions']
        dQ_window.set_focus()

Thanks in advance
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62302862

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档