How attach browser from handle?

Hello to all!

Tell me please:
If to know only the browser handle and browser type and its title, how to make attach browser?

programmatically.

Thank!

1 Like

@Aleksey_Blokhin You can use Attach Browser Activity to attach a browser. See the documentation below.

When you indicate the browser, you need to select the tab content and not the browser window.

1 Like

Hi buddy @Aleksey_Blokhin

Welcome to UiPath buddy. That’s a great question to start with

1.Attach browser can be added next to open browser activity

  1. Once you add attach browser. Use a activity called get attribute and mention as title to get the title of the browser…and type to get the type attribute

Hope this would help you buddy
Cheers

Unfortunately, these methods do not suit me.

For example, Google Chrome.

The web page contains the same title.

in other words: the selector contains the text for example,
<html app='chrome.exe' title='google.com' />

but they are all the same.

More than 3 robots are working on my process!

The only thing that is different for these browsers is the handle.

That’s why I ask, help attach it to the browser by its handle.

Attach Windows will not help with this.

Thank!!

@Aleksey_Blokhin Could you try with the details provided in the below post?

Good article!

But maybe there is a way to convert the uielement into the browser in order to transfer it to the attach browser scope, this is important!

Open Browser activity outputs a UiBrowser (Browser) object. Not sure whether you have tried that. If not, give it a try.

OK, For Example…

1. Step. Open Browser.
2. Step. Get handle of Browser → browser.Element.Get("hwnd")
3. Step. Save handle to asset
4. Step. Another process get asset with handle of browser
5. Step. Attach browser scope with this handle

My attempts:

Dim iWin As uipath.Core.Window = New uipath.Core.Window

iWin.Handle = New IntPtr(1903626)

Dim iBr As uipath.Core.Browser = New uipath.Core.Browser

Dim uiWebElement As uielement = New uielement

uiwebelement.FromWindow(iwin)

ibr.BrowserName = uipath.Core.BrowserName.Chrome

Hi Aleksey, I also need to get window by Handler.

I’ve tried to edit window-selector attributes manually (for attach window activity) to include hwnd (actually, UI Explorer is able to recognize hwnd of windows, see UI Explorer->Property Explorer). Specifying hwnd as decimal or hex does not work. May be you can be lucky enough to solve it.

One option, which works, but is far not elegant: iterate through windows of your application:

  • use dynamic selector like “wnd app=‘chrome.exe’ idx=‘0’” (add opening and closing symbols. If I add them myself, forum thinks it’s an html tag :smiley: ) by variating idx value
  • for each acquired by “attach window” UiPath.Core.Window variable, you may compare its Handle with the desired one
  • error handling, when window with such idx does not exist => stop looping
  • further steps are trivial

I guess, something like that should be possible within Invoke Code, however, I don’t know, how to access all available windows there.

If you find a better solution, let me know – it would be very helpful.

Lol, I’ve eventually found the solution. And it is one-liner:

  • wnd = New Window(handler) //if handler is IntPtr
  • wnd = New Window(new IntPtr(handler)) //if handler is integer
2 Likes

Yes, is it!!! See top:wink:

Could you please share your solution?