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