【问题标题】:Blueprism attach to window in Navigation stage with childindex not workingBlueprism 在导航阶段附加到窗口,childindex 不起作用
【发布时间】:2019-10-14 22:14:46
【问题描述】:

我正在 Blueprism 中的一个小项目上工作,在 mspaint.exe 上绘制一些示意图。 由于 BP 允许我们在类似的附加应用程序之间切换,我想从 mspaint 的第一个窗口切换到第二个窗口。 但是由于两者都没有以任何文件名保存,因此两者的窗口文本都是“无标题 - 绘画”。

在 Blueprism 中,当为一个 exe 打开多个实例时,它们都具有相同的窗口标题,无法附加到任何打开的实例。

尝试使用完全匹配或通配符匹配以及子索引选择(其中任何一个 + 导航阶段中的进程名称)进行附加,所有打开的实例都响应为真。我认为,exe(mspaint)没有给OS提供实例编号,因此BP可以识别它。

在导航阶段,给出子索引,就是给出异常:
“不止一项申请符合标准”。

如果标题相同并且无法获得子索引,那么附加窗口的常用方法是什么?有什么方法可以获取唯一的窗口句柄并使用它吗?

【问题讨论】:

  • 你能为每个实例分配不同的句柄吗?
  • 窗口句柄本身不能通过 BP 获得。我们可以通过 Memory stats 获取集合中任何特定运行进程(它的所有实例)的 PI​​D,这是我能想到的最接近和最好的方法。但是我们不能在附加时使用它,因为窗口文本是我们唯一可以在那里使用的东西。
  • 您可以编写一个代码阶段来为您的应用程序的每个实例提取单独的窗口句柄,并根据需要使用另一个通过句柄激活窗口。或者,在您打开每个实例时使用名称将文件保存在 Paint 中,并在完成后删除文件 - 这将使窗口标题不同,以便您能够在它们之间切换......
  • @Dave,OK 将尝试在代码阶段工作 - 如果我能像这样得到它会很棒,所以需要在 C# 中进行一些研发。是的,保存和获得标题是我现在正在做的事情。另外,由于 PID 已经在 BP 中可用,是否可以自定义代码以使用 PID 本身进行附加,会容易得多,对吧?

标签: blueprism rpa spying


【解决方案1】:

您可以在附加阶段通过 PID 附加到目标应用程序。这样做非常棘手,并且会导致繁琐的过程,所以虽然是的,你可以做到,但我真的会重新审视你的设计,并确保你在做正确的设计选择.

这里的图片是我绘制的快速示意图,可以满足您的需求。您可以使用实用程序环境启动过程启动应用程序,并通常为其提供目标应用程序的路径

C:\Windows\System32\mspaint.exe

一旦启动,您就可以识别每个实例的 PID 并附加到它们。当您附加时,请确保您控制您的分离/附加决策,因为一个对象一次只能附加到一个实例,因此要么有一个单独的对象来规避这一点,要么让您的操作具有非常结构化的定义良好的标准来不断管理附加和分离当您在两个应用程序之间切换时,在您的进程中。

制作图像的XML代码在这里,请阅读注释。还有一个示例附加阶段(其中有一个故意的错误)。您应该能够足够轻松地单步执行其他代码。只需将其复制粘贴到您的图表区域即可。

<process name="__selection___test" type="object" runmode="Exclusive">
<stage stageid="62af981b-d1b4-425d-9beb-5dd9663ded2b" name="Attach" type="Navigate">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        -270
    </displayx>
    <displayy>
        210
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <step>
        <element id="859d3912-cecd-4456-9be2-9bd6a73f8717" />
        <action>
            <id>
                AttachApplication
            </id>
            <arguments>
                <argument>
                    <id>
                        WindowTitlesCollection
                    </id>
                    <value>
                    </value>
                </argument>
                <argument>
                    <id>
                        WindowTitle
                    </id>
                    <value>
                    </value>
                </argument>
                <argument>
                    <id>
                        ProcessName
                    </id>
                    <value>
                    </value>
                </argument>
                <argument>
                    <id>
                        ProcessID
                    </id>
                    <value>
                        put your process id here
                    </value>
                </argument>
                <argument>
                    <id>
                        Username
                    </id>
                    <value>
                    </value>
                </argument>
                <argument>
                    <id>
                        ChildIndex
                    </id>
                    <value>
                    </value>
                </argument>
            </arguments>
        </action>
    </step>
</stage>
<stage stageid="3b3fbe62-76da-4757-846e-30deaee86f35" name="get process information" type="Action">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        15
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <inputs>
        <input type="collection" name="Process Names" narrative="The names of the processes to get memory statistics for" expr="[Processes]" />
    </inputs>
    <outputs>
        <output type="collection" name="Process Statistics" narrative="A collection of process statistics including the working set and the virtual memory size" stage="Process Statistics" />
    </outputs>
    <onsuccess>
        ba3fa046-a5c9-4bd2-b15d-26946e25c160
    </onsuccess>
    <resource object="Utility - DXW - Environment" action="Read Memory Stats" />
</stage>
<stage stageid="ef10a40e-34d6-4645-9e3e-c2abfa823b38" name="Working Set" type="Data">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        135
    </displayx>
    <displayy>
        15
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <datatype>
        number
    </datatype>
    <initialvalue />
    <private />
    <alwaysinit />
</stage>
<stage stageid="731b76e6-98a8-4e7f-879e-e576aecd82d8" name="Process Statistics" type="Collection">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        135
    </displayx>
    <displayy>
        105
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <datatype>
        collection
    </datatype>
    <private />
    <alwaysinit />
    <collectioninfo>
        <field name="Process Name" type="text" />
        <field name="PID" type="number" />
        <field name="Working Set" type="number" />
        <field name="Virtual Memory" type="number" />
    </collectioninfo>
</stage>
<stage stageid="6ffde746-c61b-45cc-83fe-b86f86cdd8af" name="Processes" type="Collection">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        135
    </displayx>
    <displayy>
        60
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <datatype>
        collection
    </datatype>
    <private />
    <alwaysinit />
    <collectioninfo>
        <field name="Processes" type="text" />
    </collectioninfo>
    <initialvalue>
        <row>
            <field name="Processes" type="text" value="mspaint" />
        </row>
    </initialvalue>
</stage>
<stage stageid="ba3fa046-a5c9-4bd2-b15d-26946e25c160" name="Note3" type="Note">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        now we have the first PID
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        75
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <onsuccess>
        2c96c44a-38c9-449d-93a2-e06e5280560f
    </onsuccess>
</stage>
<stage stageid="2c96c44a-38c9-449d-93a2-e06e5280560f" name="record PSID" type="Calculation">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        120
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <onsuccess>
        aacc1662-0c73-4dc6-a49c-aae3d2bc2485
    </onsuccess>
    <calculation expression="[Process Statistics.PID]" stage="First mspaint PID" />
</stage>
<stage stageid="586fd363-1640-4ef7-ab19-1352cc9b8861" name="First mspaint PID" type="Data">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        135
    </displayx>
    <displayy>
        165
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <datatype>
        text
    </datatype>
    <initialvalue />
    <private />
    <alwaysinit />
</stage>
<stage stageid="a7f6bfb6-5cd3-4f10-8e23-82e271515278" name="get process information" type="Action">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        240
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <inputs>
        <input type="collection" name="Process Names" narrative="The names of the processes to get memory statistics for" expr="[Processes]" />
    </inputs>
    <outputs>
        <output type="collection" name="Process Statistics" narrative="A collection of process statistics including the working set and the virtual memory size" stage="Process Statistics" />
    </outputs>
    <onsuccess>
        5b9affa9-98db-4014-98b7-4a7b559b5cd1
    </onsuccess>
    <resource object="Utility - DXW - Environment" action="Read Memory Stats" />
</stage>
<stage stageid="5b9affa9-98db-4014-98b7-4a7b559b5cd1" name="Note3" type="Note">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        now we have the second PID so we loop to find it
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        300
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <onsuccess>
        b6c496da-d5b7-4ebb-9a99-98c5fc3f29c2
    </onsuccess>
</stage>
<stage stageid="1109b7bc-dbbe-4c1c-9af1-5da02bf2a229" name="record PSID" type="Calculation">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        480
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <onsuccess>
        2ca14198-33a5-43db-b9ad-6970797c2b36
    </onsuccess>
    <calculation expression="[Process Statistics.PID]" stage="First mspaint PID" />
</stage>
<stage stageid="aacc1662-0c73-4dc6-a49c-aae3d2bc2485" name="Launch Application" type="Action">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        180
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <inputs>
        <input type="text" name="Application" narrative="The application or short cut to start" expr="&quot;C:\Windows\System32\mspaint.exe&quot;" />
        <input type="text" name="Arguments" narrative="Any arguments needed for the app" expr="" />
    </inputs>
    <onsuccess>
        a7f6bfb6-5cd3-4f10-8e23-82e271515278
    </onsuccess>
    <resource object="Utility - DXW - Environment" action="Start Process" />
</stage>
<stage stageid="b6c496da-d5b7-4ebb-9a99-98c5fc3f29c2" name="loop PIDs found" type="LoopStart">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        360
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <onsuccess>
        f00d91ee-116d-44e1-8d42-a7cb23c9983e
    </onsuccess>
    <groupid>
        f4c4a30f-44b1-4c6a-a632-a1b46719e8d1
    </groupid>
    <looptype>
        ForEach
    </looptype>
    <loopdata>
        Process Statistics
    </loopdata>
</stage>
<stage stageid="2ca14198-33a5-43db-b9ad-6970797c2b36" name="loop PIDs found" type="LoopEnd">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
        
        
        
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        540
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <onsuccess>
        cb91afa2-8a34-4fda-82a6-d95335ce534e
    </onsuccess>
    <groupid>
        f4c4a30f-44b1-4c6a-a632-a1b46719e8d1
    </groupid>
</stage>
<stage stageid="ec0a4f36-ac09-4959-82c9-1bedadb63258" name="Second msPaint PID" type="Data">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        180
    </displayx>
    <displayy>
        480
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <datatype>
        text
    </datatype>
    <initialvalue />
    <private />
    <alwaysinit />
</stage>
<stage stageid="cb91afa2-8a34-4fda-82a6-d95335ce534e" name="Note4" type="Note">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        now perform your attach functions. remember an object can only attach to one thing at a time so either make a new object to have one for each instance or make one object and have strict control over your attach and detach functions
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        600
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
</stage>
<stage stageid="f00d91ee-116d-44e1-8d42-a7cb23c9983e" name="Is it the same PID?" type="Decision">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        420
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <decision expression="[Process Statistics.PID]=[First mspaint PID]" />
    <ontrue>
        cafab8cb-4d5e-48d9-872f-07f3a6b4cd65
    </ontrue>
    <onfalse>
        1109b7bc-dbbe-4c1c-9af1-5da02bf2a229
    </onfalse>
</stage>
<stage stageid="cafab8cb-4d5e-48d9-872f-07f3a6b4cd65" name="Anchor1" type="Anchor">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
    </narrative>
    <displayx>
        90
    </displayx>
    <displayy>
        420
    </displayy>
    <displaywidth>
        10
    </displaywidth>
    <displayheight>
        10
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <onsuccess>
        9eabbb67-c740-4376-b9e9-4ec0db2ef909
    </onsuccess>
</stage>
<stage stageid="9eabbb67-c740-4376-b9e9-4ec0db2ef909" name="Anchor2" type="Anchor">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
    </narrative>
    <displayx>
        90
    </displayx>
    <displayy>
        540
    </displayy>
    <displaywidth>
        10
    </displaywidth>
    <displayheight>
        10
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <onsuccess>
        2ca14198-33a5-43db-b9ad-6970797c2b36
    </onsuccess>
</stage>
<stage stageid="ee281457-bd05-497a-b11d-01aff60efc6b" name="Launch Application" type="Action">
    <subsheetid>
        6baeaef9-1401-45ea-8782-baec374c4b4c
    </subsheetid>
    <loginhibit />
    <narrative>
        Dexter was here 21/03/2020 don't delete me maybe i'll work with you someday we can laugh about this description.
    </narrative>
    <displayx>
        15
    </displayx>
    <displayy>
        -45
    </displayy>
    <displaywidth>
        60
    </displaywidth>
    <displayheight>
        30
    </displayheight>
    <font family="Segoe UI" size="10" style="Regular" color="000000" />
    <inputs>
        <input type="text" name="Application" narrative="The application or short cut to start" expr="&quot;C:\Windows\System32\mspaint.exe&quot;" />
        <input type="text" name="Arguments" narrative="Any arguments needed for the app" expr="" />
    </inputs>
    <onsuccess>
        3b3fbe62-76da-4757-846e-30deaee86f35
    </onsuccess>
    <resource object="Utility - DXW - Environment" action="Start Process" />
</stage>
</process>

【讨论】:

  • Dexter,很抱歉,由于锁定(因此迟到了评论),BP PC 有一段时间没有工作了。然后我尝试导入你的 XML 文件,它给出了附件错误(你说你是故意放的)。看原理图我不知道你到底是什么意思。正如第一手所说,是的,获得 PID 是可能的,但是通过将 PID 提供给 BP 来附加永远不会起作用。你是不是用了其他方式?为什么会出现错误 - 没有导入,我该如何分析?
  • XML 文件的最后一行: 也不见了。
  • 如果你打算附加到第一个实例并检查存储的 PID,如果不是需要的,分离和附加另一个将不起作用,因为第一个附加阶段本身会出错。或者也许我在这里错过了一些东西。感谢您尝试提供如此详细的帮助。
  • “通过将 PID 提供给 BP 将永远无法连接”是什么意思? Ans : 我所说的是,在 BP 中,没有选项可以告诉 BP 的“附加阶段”附加到具有特定 PID 的窗口。我看到的唯一选项是:Win Title (collection)、Win Title、Proc name、Child Index。我们可以测试并找出哪个窗口有什么 PID,但是我如何告诉 BP 在附加时要特别注意那个窗口呢?我使用的是 BP 版本 5.x。
  • 我明白了你想说的。分析您的 XML 文件,我发现:您使用的是最新版本的 BP,其中还有一个名为“AttachApplication”的附加阶段,它有 2 个额外的参数:ProcessID、用户名。这就是为什么我什至无法导入您的 XML 文件并进行分析的原因。我的 BP(旧版本)中缺少这些。所以案例已结束(最新的 BP 版本已修复问题)。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多