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.
alright thx bro!
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
Is that possible to close 2 tab ? cuz when i use close web browser, it just close one tab
Hi @Th11
Try this logic
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
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.
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.
eetuRobo
11
Super User 2025 Season 1
KO-05050229-0
4
stampcoin
2