web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Automate
Unanswered

Closing browser tab

(0) ShareShare
ReportReport
Posted on 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.

 

I have the same question (0)
  • Verified answer
    Highboy Profile Picture
    1,183 Super User 2024 Season 1 on at

    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.

     

  • Th11 Profile Picture
    on at

    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
    Nived_Nambiar Profile Picture
    18,129 Super User 2025 Season 2 on at

    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 

     

     

  • YeuHarng Profile Picture
    48 on at

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

  • kinuasa Profile Picture
    795 Most Valuable Professional on at

    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 at

    alright thx bro!

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard