How to close tab if a more than one tab is present in internet explorer

I have below requirement.
There are two tabs in internet explorer. I want to close a tab based on a specific element(a link) exist on that tab.
Can anyone help me how should i achieve this?
Or is there any way in which i can activate a browser window where my specifc UI element exist?
Thanks and Regards,

1 Like

Once you identify the specific element exist use following shortcut

  • ctl+1(for the first tab)…2,3,4 on so on. which will focus the tab.

  • ctl+w to close that visible tab

you can make use of close Tab activity and pass the browser variable(make sure you create browser variable for each tab)

Well, I dont want to browse through tabs using ctrl+1,2 and so on.

I want to do following things.

  1. I am opening a browser and clicking on link, which inturn is opening a new tab in the same browser. Now, I want to close the first tab which i opened throough open browser activity. For that, i am checking if a “Home Link” is present or not. But, Robot is not taking control to that tab… It remains on the second tab.

So, My question is, is there an activity in UI Path, which finds the element on the tab and activate the tab.?

Please note that here, both the tabs have same title.

For “Close tab” activity, It would be really helpful if you can provide any example since i am quite new to UIPath.


Here we go.
closeTab.xaml (9 KB)

Hi @vishalgajjar11,

One more thing that you can also do is to get the URL from the HTML link and use the Navigato To activity.

It will open that specific link on the same tab.

Hi ddpadil
Question: how do you create a browser variable for this purpose?

Hi @Gary_How,

In Open Browser activity -> Properties UiBrowser ->create the browser variable.


Hi Arivu

Thanks for the prompt response. However this is for the first tab. What if
I open a 2nd tab, 3rd, 4th tab? How do i create browser variable for each
of them?

Appreciate you help :slight_smile:

Hi @Gary_How,

Here the firstTab variable is Browser its not related to TAB.
Browser variable contains all the tab.

Refer this


Hi Arivu

ddpadil mentioned: “(make sure you create browser variable for each tab)”
I wanted to know how to create browser variable for each new tab?

hi @Gary_How,

you can use the send hot key to close the tabs.

here close tab activity is used to close the initial tab or first tab alone. If you want to close other tabs use send hot key to close


Hi @arivu96

Thank you for your reply. I am able to close the tab. but I just want to know the below:

@ddpadil mentioned: “(make sure you create browser variable for each tab)”
I wanted to know how to create browser variable for each new tab?

Attach Browser or Attach Window, then Create a Variable in the UiBrowser or Window Output property.
It basically just stores the selector information though so isn’t always needed but keeps it organized. You can use this variable in the Close tab or Close Window activities instead of the selector. If you use Close Window you need to click the button for Close Current tab that comes up (but works well, so use either method).


Hi @ClaytonM

My situation is that i already have a Attach Browser i.e. tab1
Within this, I used a Hot Key (“ctrl + T”) to create a new tab i.e. tab 2.

I have no problem creating a variable for tab1 but
how do i create a variable for tab2 which is automatically opened by the hot key (ctrl + t) within the first Attach Browser for tab1?


You can use another Attach Browser or Attach Window on the tab2. It’s normally good practice to use a new Attach activity for every window, tab, or popup that gets opened.

Hope that answers it.



hi @ClaytonM i am trying very hard to understand what you are trying to advice but to no avail.
Thanks for your help. I think I will create a new thread for my problem .