the handle do not return from the new tab, because this tab does not have time to create
Fixed _WD_NewTab
Func _WD_NewTab($sSession, $lSwitch = True)
Local Const $sFuncName = "_WD_NewTab"
Local $sTabHandle = ''
Local $TimerNewTab = 0
_WD_ExecuteScript($sSession, 'window.open()', '{}')
$TimerNewTab = TimerInit()
While 1
If TimerDiff($TimerNewTab) > 5000 Then Return SetError($_WD_ERROR_Success, 0, $sTabHandle)
If @error = $_WD_ERROR_Success Then
Local $aHandles = _WD_Window($sSession, 'handles', '')
$sTabHandle = $aHandles[UBound($aHandles) - 1]
If $lSwitch Then
_WD_Window($sSession, 'Switch', '{"handle":"' & $sTabHandle & '"}')
EndIf
ExitLoop
EndIf
Sleep(10)
WEnd
Return SetError($_WD_ERROR_Success, 0, $sTabHandle)
EndFunc ;==>_WD_NewTab
Now, if the tab is not created within 5 seconds, it returns an SetError