Blueprism attach to window in Navigation stage with childindex not working

2.9k Views Asked by At

I'm working on a small proj in Blueprism, on mspaint.exe to draw few schematics. As BP allows us to switch between similar attached apps, I want to switch from first window to second window of mspaint. But as both are not saved with any file-name, the windows text is "Untitled - Paint" for both.

In Blueprism, when there are more than 1 instances open for an exe, all with same window title, cannot attach to any open instance.

Tried attaching with exact or wildcard match as well as child-index selection (any one of them + process name in nav. stage), all open instances respond true. I think that, there is no instance number given by the exe (mspaint) to OS, so that BP can identify it.

In Navigation stage, giving the child-index, is giving exception :
"More than one application matched the criteria".

If title is same and child-index is unobtainable, what is the usual way to attach a window? Is there any method to get the unique window-handle and use it?

1

There are 1 best solutions below

8
On

you can attach to a target application via PID in your attach stage. Doing it this way is very very tricky and will make for a cumbersome process so though yes you can do it, I'd really re-visit your design and make sure you're doing the right design choices.

enter image description here

The image here is a quick schematic I drew up which does what you're looking for. you can launch the application with utility environment launch process and proivde it the path to the target application usually

C:\Windows\System32\mspaint.exe

once launched you can then identify the PID of each instance and attach to them. When you attach make sure you control your detach/attach decisions as an object can only attach to one instance at a time so either have a seperate object to circumvent this or have your actions have very structured well-defined criteria to manage attach and detaching constantly in your process as you switch between two applications.

the XML code to do the image is here, please read the notes. There is also a sample attach stage (with a purposeful error in it). You should be able to step through the other code easily enough. Just copy paste it into your diagram area.

<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>