How do I close all Chrome windows/tabs except one?

Have this annoying app I’m trying to automate in, and it has a habit of opening secondary windows that interfere with the automation. These windows are opening automatically, not in response to any action taken by the automation.

So at a certain point I want to close any and all chrome windows/tabs except the main window/tab which I have in a UI Element variable.

@postwick We use FindChildren activity to find the all chrome instances and close them using close window activity but in your case, you can use FindChildren Activity to find all the chrome instances, go through for each activity/each instance and validate if your current Ui element (Assuming you have it in variable) is matching with for each current instance, if it is matching then dont close it other wise close it using close window activity

Can you share details of how you configured Find Children? I tried it but could not get it to work.

Oh I just figured it out!

Selector: "<wnd app='chrome.exe' />"
Filter: "<html app='chrome.exe' />"
Scope: FindScope.FIND_TOP_LEVELS

I already have the original window the automation opened in a UI Element variable. I can use its unique identifier “hwnd” to close everything except that window. You can easily get title, url, hwnd, and processid (for the underlying Windows process) with .Get:

I noticed that sometimes multiple Chrome tabs/windows will have the same hwnd, and they always have the same PID and TID.

Turns out it’s much simpler, you can directly compare the UI Elements. This appears reliable so far with limited testing.

UIElementA.Equals(UIElementB)

Just that simple. I don’t know what comparison UiPath is doing, but it works.

By the way, for my purposes I also used a url filter in Find Children with wildcards to focus on a specific web app.

"<html app='chrome.exe' url='*deluxe.com*' />"

@postwick Glad to hear, you are able to solve it