"UiElement is no longer valid" when workflow starts with closed browser

uiautomation
activities
chrome
studio
error

#1

Hello,

Could you please explain why my workflow gives an error when my browser is closed?

My workflow starts with opening Chrome and typing a URL into the search bar.

  • If I start the workflow with Chrome already open, it opens a new Chrome window. Then it switches to the original window and types the URL in the search bar.
  • If I start the workflow without Chrome open, it opens a new Chrome window. Then within two seconds it gives the following error:

[Window Title]
Workflow Exception

[Main Instruction]
Main has thrown an exception

[Content]
Source: Browser window scope

Message: The UiElement is no longer valid

Exception Type: InvalidUiElementException

[Expanded Information]
UiPath.Core.InvalidUiElementException: The UiElement is no longer valid —> System.Runtime.InteropServices.COMException: Invalid UI node
at UiPath.UiNodeClass.GetTopLevelWindow()
at UiPath.Core.UiElement.GetTopLevelWindow()
— End of inner exception stack trace —
at UiPath.Core.Activities.ScopeActivity.EndExecute(NativeActivityContext context, IAsyncResult result)
at UiPath.Core.Activities.AsyncNativeActivity.BookmarkResumptionCallback(NativeActivityContext context, Bookmark bookmark, Object value)
at System.Activities.Runtime.BookmarkCallbackWrapper.Invoke(NativeActivityContext context, Bookmark bookmark, Object value)
at System.Activities.Runtime.BookmarkWorkItem.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager)

This is what the start of my workflow looks like:

This is the selector I am using as an input into the WindowScope activity. (There is a < symbol between the " and the html.)

“html app=‘chrome.exe’ />”

I have looked at the other threads with “UiElement is no longer valid” and I don’t think this is the same issue.
I have tried remaking the workflow with Firefox, but I’m encountering a different error there. I’d like to solve this in Chrome before figuring out other browsers.


#2

Hi,
It’s just a matter of finding static selector.
In Typeinto all you have is just browser attribute .
You need to get address bar selector for ex: like below.

 <ctrl name='main' role='tool bar' />
<ctrl name='Address and search bar' role='editable text' />

To avoid start process ,attach browser,TypeInto and selector problem you could have just used Open browser activity and just pass the URL .Work with all 3 browser :slight_smile:


#3

Thanks @ddpadil, the error went away when I used the right selector.
The Open browser activity also worked and made the workflow much simpler.