Has to wait for WebWindows to be fully ready?? #132
-
Hello @GCuser99 and @6DiegoDiego9 I created my own function finding the new window/tab in case there are already multi-windows/tabs existing. However, I have to add the "sleep 1000" (has to wait sometime) at the beginning of the function. Otherwise, I will definitely get the error as shown in the picture. With this "sleep 1000", everything is working fine! Is this somthing that could be improved?
|
Beta Was this translation helpful? Give feedback.
Answered by
GCuser99
Oct 31, 2024
Replies: 1 comment 1 reply
-
Here is one alternative: Function GetNewBrowserWindow(oldWindows As WebWindows, driver As WebDriver) As WebWindow
'need to give the new window some time to be created after click event
Do While driver.Windows.Count = oldWindows.Count
driver.Wait 100
DoEvents
Loop
'------------------------------------------------------------------------------------------------------
'I know this goes against the Selenium advice that we can't assume a window order
'in Windows collection but you may want to test if the last window created is last
'in the collection - it works for me as an alternative to enumerating the Windows collection:
'Set GetNewBrowserWindow = driver.Windows(driver.Windows.Count)
'Exit Function
'------------------------------------------------------------------------------------------------------
'but this below works fine for me too...
Dim oldWindow As WebWindow
Dim newWindow As WebWindow
Dim blnFound As Boolean
For Each newWindow In driver.Windows
blnFound = False
For Each oldWindow In oldWindows
If oldWindow.IsSameAs(newWindow) Then
blnFound = True
Exit For
End If
Next oldWindow
If Not blnFound Then
Set GetNewBrowserWindow = newWindow
Exit Function
End If
Next newWindow
End Function ' Click that opens a new tab
Set oldWindows = objChrome.Windows
e.Click
'yes @GHRyunosuke, the new window takes some time to be created after click...
' SwitchTo the new tab among already existing tabs
Set newWindow = GetNewBrowserWindow(oldWindows, objChrome)
newWindow.Activate |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
GHRyunosuke
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is one alternative: