Switching to child window in a desktop application

Hello, I am new to Robocorp. I am automating a windows desktop application. The application has multiple child windows. I have the part done for opening the application and sending keys to opening a child screen but I am having hard time in switching to the child window or basically to do the operations on the child window. Right now, whenever I use the keyword wait for element (using the locator of the child screen) it ends up with the error ElementNotFoundError. I have used, keywords - Refresh Window, Control Window and Control Child Window and still I am getting the error. Any help, highly appreciated.

*** Settings ***
Documentation       Sample robot1
Library    RPA.Windows
Library    RPA.Desktop.Windows
Library    Process

*** Tasks ***
Open Application and Start Processing
    Open App
    Set Up Environment
    Open Vendor Invoice Entry Screen
    Enter Invoice

*** Keywords ***
Open App
    Run Process    ${path}    ${args}    cwd=${dir}  
    Sleep    10s    

Set Up Environment
    @{windows}    Get Window List   
    FOR  ${window}  IN  @{windows} 
        ${found}=   Run Keyword And Return Status  Should Contain  '${window}[title]'  ${title}   
        IF  ${found}
           Set Task Variable  ${HANDLE}    ${window}[handle]
    ${appid}=   Connect By Handle   ${HANDLE}

Open Vendor Invoice Entry Screen
    Wait For Element    name:Accounting
    RPA.Desktop.Windows.Send Keys   %apv
    Sleep    5s

Enter Invoice
    Refresh Window
    Sleep    2s
    Wait For Element    name:Post Entry 	     #ERROR -  ElementNotFoundError
    #Control Window     regex:${title}.*
    #Control Child Window    name: Vendor Invoice Entry	#ERROR - WindowControlError: Could not locate window with locator: 'name:Vendor Invoice Entry' (timeout: 10)

You can switch between windows by using Control Window.
On high level something like

Wait For Window    Sign In
Control Window    name:"Sign In"
Click    control:TitleBarControl > control:ButtonControl

You can check Robocorp Portal for some examples.
Also there should be no need to mix usage of RPA.Desktop.Windows and RPA.Windows library.

Hi @linkraivo thanks for your reply. I tried what you suggested but that didn’t work. Basically the bot is not able to detect the elements of the child screen.

  1. Have you tried with a looser locator like: Control Window subname:Invoice? (or ... regex:Vendor.+)
  2. If that doesn’t work, please take a look at How to inspect header under docs. Where beside the Accessibility Insights tool you’re using, you have two more options:
    • Use windows-record tool, then click over elements to see their locators. (after pressing ESC to end the recording)
    • See what Print Tree log_as_warnings=${True} outputs so you know how the elements are recognized by the library.
  3. Control Child Window sets as root element the currently active window, but there’s no guarantee that those children windows have as a parent in the element tree the initial one you were controlling previously. (although I may be wrong here since in your screenshot it looks like you’re having a window under another window)

If you still can’t get it solved, is it possible to share the app so we/I can replicate and find a fix? Thank you!

Hi @cosmin, that was the exact issue. Thanks a lot. I am now able to recognize the screen and inputting the data into text fields, but I sometimes find issues in clicking on a button using RPA.Windows.Click keyword. Sometimes it clicks the button and sometimes not. In the Log it does shows that it clicked on the button successfully. Any idea on that? Thanks in advance. FYI, I already done what have mentioned in this thread - Click method not working - #2 by cosmin

No clue here about the intermittent behaviour, maybe it is because it takes some time for the app to be ready to acknowledge the click? (check out the wait_time parameter with various such keywords which can delay a past action until getting to the next one)

Meanwhile, maybe a workaround using keyboard keys pressing with Send Keys will lead to stabler automation.