How to close all pages of browser

Excuse me, I am a freshman to use Uipath, I wish I could close all pages of browser. I had tried
to use “close tab”, but it can only close one page instead of the whole page.

Please help me, thanks!!

@MJ_LEE

Welcome to forums

You can try with Kill process and pass chrome in process name

This will close the session of the chrome browser

Hope this may help you

Thanks

Hi @MJ_LEE ,

You can use as shown below and don’t forget to select only current user if you have multiple use machine for same server.

You can use either chrome or IE.

Thank for replied, but why I use the same activity but it does not display the properties to use.

My be there is a difference in version, leave it for now.

Hi

We can just use Kill process with ProcessName mentioned as “chrome” which will either kill the entire browser

If you would like to see the latest one go to
Design tab → Manage Packages → Project Dependencies

There upgrade UiPath.System.Activities and UiPath and UiPath.UIAutomation.Activties

Cheers @MJ_LEE

1 Like

You can use “close tab” activity or hotkey with CTRL + W.

1 Like

thanks for all, Finally I used “kill process” to solve this problem.

But I have another problem arises

"How to detect the browser exist? "
I have tried use " if " this activity but I don’t know how to setup about variable

You can try with element exists activity
Cheers @MJ_LEE

Hi,

To check if the process is running, you can use a “If” with :

System.Diagnostics.Process.GetProcesses().AsEnumerable().Any(prcRunning=> prcRunning.ProcessName.ToLower().Trim() == strProcessName.ToLower().Trim());

where strProcessName is the name of the process, eg msedge.

To close all tabs, you don’t need Kill Processes because it really “kills”, so when you’ll open again your browser, you can have a pop-up “restore pages” which can disturb your bot. You can simply use a Close Window inside an attach browser and it will close every tab.

Good luck!

Kill Process isn’t a good solution. If you have a server that is running multiple automations under multiple Robots, the Kill Process tries to kill it for all users. One of two things will happen:

  • it doesn’t have the necessary permissions to kill processes for other users, so the Kill Process faults

  • it does have the necessary permissions to kill processes for other users, so the Kill Process succeeds, kills the process for other users potentially breaking another job that is running at the same time

The best way to close all browser windows is with a Do While. Do an element exists with a simple selector (ie <html app="chrome.exe" />) to see if any browser windows exist. That’ll be your Do While condition - it should run until the Element Exists returns false. If it does find a browser window Attach (or Use if modern) to it and close it.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.