Skip to main content

Notifications

Community site session details

Community site session details

Session Id : 06KIJT8lPI8Dj+WTpsOChT
Power Automate - Power Automate Desktop
Answered

Closing browser tab

Like (0) ShareShare
ReportReport
Posted on 6 Jun 2023 19:47:14 by

Im working on a workflow using power automate desktop. Web application is opening multiple child web Tab. Can anyone let me know how to close the child web tab using Power Automate Desktop(PAD).  i tried send keys option eg Ctrl W and also Ctrl F4. but it's not working.

 

  • YeuHarng Profile Picture
    48 on 04 Aug 2023 at 08:02:56
    Re: Closing browser tab

    alright thx bro!

     

  • kinuasa Profile Picture
    781 Most Valuable Professional on 04 Aug 2023 at 05:14:17
    Re: Closing browser tab

    Although this is an example, You can use script as below to close tabs.

     

     

    #PowerShell script to close browser tabs with UI Automation
    
    #Strings contained in the tab title
    $tabTitle = "Google"
    #Browser window handle
    $browserHandle = 1234567
    
    #UI Automation
    Add-Type -AssemblyName "UIAutomationClient"
    Add-Type -AssemblyName "UIAutomationTypes"
    $uiAuto = [System.Windows.Automation.AutomationElement]
    $pcdn = [System.Windows.Automation.PropertyCondition]
    $tree = [System.Windows.Automation.TreeScope]
    
    $elmEdgeWindow = $uiAuto::FromHandle($browserHandle)
    if($elmEdgeWindow -ne $null){
     $cndTabBar = New-Object $pcdn($uiAuto::ClassNameProperty, "TabStripRegionView")
     $elmTabBar = $elmEdgeWindow.FindFirst($tree::Subtree, $cndTabBar)
     if($elmTabBar -ne $null){
     $cndTabStrip = New-Object $pcdn($uiAuto::ClassNameProperty, "TabStrip")
     $elmTabStrip = $elmTabBar.FindFirst($tree::Children, $cndTabStrip)
     if($elmTabStrip -ne $null){
     $cndTabItems = New-Object $pcdn($uiAuto::ControlTypeProperty, [System.Windows.Automation.ControlType]::TabItem)
     foreach($elmTabItem in $elmTabStrip.FindAll($tree::Subtree, $cndTabItems)){
     if($elmTabItem.Current.Name.Contains($tabTitle)){
     $cndTabCloseButton = New-Object $pcdn($uiAuto::ClassNameProperty, "TabCloseButton")
     $elmTabCloseButton = $elmTabItem.FindFirst($tree::Children, $cndTabCloseButton)
     if($elmTabCloseButton -ne $null){
     $ivkTabCloseButton = $elmTabCloseButton.GetCurrentPattern([System.Windows.Automation.InvokePattern]::Pattern)
     $ivkTabCloseButton.Invoke()
     }
     }
     }
     }
     }
    }

     

     

    The code below is a sample flow:

     

    SET TabTitle TO $'''Google'''
    WebAutomation.LaunchEdge.LaunchEdge Url: $'''https://powerusers.microsoft.com/''' WindowState: WebAutomation.BrowserWindowState.Normal ClearCache: False ClearCookies: False WaitForPageToLoadTimeout: 60 Timeout: 60 BrowserInstance=> Browser
    WebAutomation.CreateNewTab.CreateNewTab BrowserInstance: Browser Url: $'''https://www.google.com/''' WaitForPageToLoadTimeout: 60 NewBrowserInstance=> NewBrowser
    WebAutomation.CreateNewTab.CreateNewTab BrowserInstance: Browser Url: $'''https://www.bing.com/''' WaitForPageToLoadTimeout: 60 NewBrowserInstance=> NewBrowser
    WebAutomation.CreateNewTab.CreateNewTab BrowserInstance: Browser Url: $'''https://www.google.com/''' WaitForPageToLoadTimeout: 60 NewBrowserInstance=> NewBrowser
    Scripting.RunPowershellScript Script: $'''#PowerShell script to close browser tabs with UI Automation
    
    #Strings contained in the tab title
    $tabTitle = \"%TabTitle%\"
    #Browser window handle
    $browserHandle = %Browser.Handle%
    
    #UI Automation
    Add-Type -AssemblyName \"UIAutomationClient\"
    Add-Type -AssemblyName \"UIAutomationTypes\"
    $uiAuto = [System.Windows.Automation.AutomationElement]
    $pcdn = [System.Windows.Automation.PropertyCondition]
    $tree = [System.Windows.Automation.TreeScope]
    
    $elmEdgeWindow = $uiAuto::FromHandle($browserHandle)
    if($elmEdgeWindow -ne $null){
     $cndTabBar = New-Object $pcdn($uiAuto::ClassNameProperty, \"TabStripRegionView\")
     $elmTabBar = $elmEdgeWindow.FindFirst($tree::Subtree, $cndTabBar)
     if($elmTabBar -ne $null){
     $cndTabStrip = New-Object $pcdn($uiAuto::ClassNameProperty, \"TabStrip\")
     $elmTabStrip = $elmTabBar.FindFirst($tree::Children, $cndTabStrip)
     if($elmTabStrip -ne $null){
     $cndTabItems = New-Object $pcdn($uiAuto::ControlTypeProperty, [System.Windows.Automation.ControlType]::TabItem)
     foreach($elmTabItem in $elmTabStrip.FindAll($tree::Subtree, $cndTabItems)){
     if($elmTabItem.Current.Name.Contains($tabTitle)){
     $cndTabCloseButton = New-Object $pcdn($uiAuto::ClassNameProperty, \"TabCloseButton\")
     $elmTabCloseButton = $elmTabItem.FindFirst($tree::Children, $cndTabCloseButton)
     if($elmTabCloseButton -ne $null){
     $ivkTabCloseButton = $elmTabCloseButton.GetCurrentPattern([System.Windows.Automation.InvokePattern]::Pattern)
     $ivkTabCloseButton.Invoke()
     }
     }
     }
     }
     }
    }''' ScriptOutput=> PowershellOutput

     

  • YeuHarng Profile Picture
    48 on 03 Aug 2023 at 09:39:16
    Closing Mutiple Tab

    Is that possible to close 2 tab ? cuz when i use close web browser, it just close one tab 

  • Verified answer
    Nived_Nambiar Profile Picture
    17,554 Super User 2025 Season 1 on 13 Jun 2023 at 02:59:38
    Re: Closing browser tab

    Hi @Th11 

     

    Try this logic 

    Nived_Nambiar_0-1686625055479.png

     

    first you should launched a web session in edge (in my case i have attached at first step for demo purposes)

     

    for demo purposes bot has clicked on a link which opens a new tab

     

    Next bot will attach that tab by finding using the title and then finally close it using browser session variable using close web browser

     

    I think it would have limiatation when comes to title which may dynamically changes 

     

     

  • Th11 Profile Picture
    on 12 Jun 2023 at 03:30:56
    Re: Closing browser tab

    HI @Highboy , Many thanks for your reply. In my scenario, clicking the attachment link opens a new tab where I may attach the file and continue the procedure. In order to "launch a new Chrome" for the recently opened tab, I attempted to. But for some reason it didn't turn out. Could you kindly send the screenshot for the circumstance mentioned above? Thanks!

     

    Regards,

    Thulasi.

  • Verified answer
    Highboy Profile Picture
    1,161 Super User 2024 Season 1 on 09 Jun 2023 at 07:50:26
    Re: Closing browser tab

    I have had the same problem, and solved it like this.
    When a tab is opend, I "launch" a new edge and attach it to the "tab".
    The when I have to close the tab, I just close the newly opend web browser instance, and it will then close the tab, and not the original brows, that spawned the tab.
    Still can't figure out why they wont add a "Close tab in edge" function.

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Power Automate Desktop

#1
eetuRobo Profile Picture

eetuRobo 11 Super User 2025 Season 1

#2
KO-05050229-0 Profile Picture

KO-05050229-0 4

#3
stampcoin Profile Picture

stampcoin 2

Overall leaderboard