Wait until Excel file was opened - Find Element

Hi all, what is the best practice (“activity”) to ensure/wait that an Excel file was loaded/opened? We used a “find element” (WaitUIElementAppear) activity - but from time to time it fails, i.e. UIPath does not “recognize” that the Excel application was already opened, i.e. the Excel file was loaded/opened. It’s really annoying as we can not reproduce that error.
Note:

  1. The Excel application is opened by SAP automatically - so we can’t use the Excel Application Scope.
  2. The overall objective is to wait until SAP has opened the mentioned Excel file and close the whole Excel application afterwards.

Thx a lot for your support!

1 Like

Hello @thomas.beer,

you can use this activity Element Exists to check for element to appear and then do your activities which are needed after Excel is opened.

For another approach you can kill Excel process and then open it with Excel Application Scope if you know here this Excel is stored.

Cheers,
Dino

1 Like

Have you tried troubleshooting to determine the reason why it is intermittently failing? Is it due to a timeout issue, or is it something else? I would continue down that route, or if it’s just random then I would simply surround that area in a try-catch or a retry activity so that the errors are caught and you retry using SAP to open the excel document again x number of times until it works (you set the MaxRetry to whatever is appropriate to the situation)

Other options if you wish to try are to look at active window titles and see if any contain the word excel. If they do, you can use the attach window activity on that process.

If you have to do a significant amount of processing within excel, I would agree that the best course of action once you’ve attached the window is to immediately save it to a temp location, close it, then reopen it with the excel application scope. This makes it much quicker to work with and less error-prone

1 Like

Hi Dino, hi Dave, thx for your support.
The reason of “failing” is always the timeout, i.e. Excel was started and the file was loaded but is not recognized by the “Find Element” activity (the timeout is also set to a very high value).
At least that was my assumption - because I was convinced that I cant trust “SAP” (respectively the UIPath workflow which is forcing SAP to open the Excel file) and that SAP is opening the Excel file absolutely reliable.
In the meanwhile I’m doubting - therefore I was adding verbose debug information (e.g. a screenshot to see if the Excel file was really opened).
Maybe I was blaming the “find element” activity without legal cause :wink:

Regarding the second part of your answer: I don’t have a significant work of Excel processing - its just waiting still SAP has opened that Excel file and closing the whole Excel application afterwards. The “challenge” is to detect when the file was loaded (i.e. Excel was successfully started and opened the file) - as “Find element” is working in 95% of the cases but from time to time it fails.

I hope that the enhanced debug information will help to solve that issue.

Thx,
TB

How about using Get Processes Activity to check if any Excel is opened, if yes then you can use kill process to close the same?

@thomas.beer
we implemented such scenarios a few times in our projects and were dealing with the same question. The main strategies are given by Dino / Dave:

element approach: using attach, find element /element exists …

  • here we would recommend to combine it with a retry scope activity
    • keep in mind the different usages of retry scope (e.g. without check condition it is repeated until the action block is not throwing an exception)

process approach Process.GetProcessByName and react on Excel processes, check the Process.MainWindowTitle property

From viewpoint of robustness the process approach was not reliable working on all Evironments (DEV = super, PROD - failed too often) and there was not hint to find the explanation. So we implemented both approach within a cascade (fall back in case of the first approach did not work)

One helpfull thing was following. getting the window variable from a process:
window = new Window(YourProcessVar.MainWindowHandle)

so give a try and let us know your results

1 Like