Reputation: 9538
I am trying to do the following: Navigate to a specific url then in the second loop, I would like to close the existing tab for some reasons of getting information correctly (as a new start) So I would like to open a new tab and close the previous tab This is my try
If f = True Then
''.Refresh
.ExecuteScript "window.open('');"
.SwitchToNextWindow
.Windows.Item(.Windows.Count - 1).Close
''.SwitchToPreviousWindow
''.Close
' .SwitchToNextWindow
End If
.Get sBaseURL
I got an error after cloing the tab and when trying to naviagte the url for the second time
NoSuchWindowError
I could solve the first part by creating a new tab and naviagting to the new tab
If f = True Then
Stop
.ExecuteScript "window.open(arguments[0])", sBaseURL
.SwitchToNextWindow
''.Windows.Item(.Windows.Count - 1).Close
End If
But I couldn't close the previous window (tab)
.Windows.Item(.Windows.Count - 1).Close
As when trying to activate this line of closing the previous window, I got the error NoSuchWindowError
Upvotes: 0
Views: 1031
Reputation: 9538
I could solve the problem by using these lines
If f = True Then
.ExecuteScript "window.open(arguments[0])", sBaseURL
.SwitchToNextWindow
.Windows(1).Close
.Windows(1).Activate
End If
But I welcome any ideas or solutions
Upvotes: 1