@@ -538,36 +538,70 @@ EndFunc ;==>_WD_IsWindowTop
538
538
; Description ...: Enter the specified frame.
539
539
; Syntax ........: _WD_FrameEnter($sSession, $vIdentifier)
540
540
; Parameters ....: $sSession - Session ID from _WD_CreateSession
541
- ; $vIdentifier - Index (as 0-based Integer) or Element ID (as String) or Null (Keyword)
541
+ ; $vIdentifier - Target frame identifier. Can be any of the following:
542
+ ; |Null - Return to top-most browsing context
543
+ ; |String - Element ID from _WD_FindElement or path like 'null/2/0'
544
+ ; |Integer - 0-based index of frames
542
545
; Return values .: Success - True.
543
- ; Failure - WD Response error message (E.g. "no such frame") and sets @error to $_WD_ERROR_Exception
546
+ ; Failure - WD Response error message (E.g. "no such frame") and sets @error to one of the following values:
547
+ ; - $_WD_ERROR_Exception
548
+ ; - $_WD_ERROR_InvalidArgue
544
549
; Author ........: Decibel
545
- ; Modified ......: mLipok
546
- ; Remarks .......: You can drill-down into nested frames by calling this function repeatedly with the correct parameters.
550
+ ; Modified ......: Danp2, mLipok, jchd
551
+ ; Remarks .......: You can drill-down into nested frames by calling this function repeatedly or use identifier like 'null/2/0'
547
552
; Related .......: _WD_Window, _WD_LastHTTPResult
548
553
; Link ..........:
549
554
; Example .......: No
550
555
; ===============================================================================================================================
551
556
Func _WD_FrameEnter($sSession , $vIdentifier )
552
557
Local Const $sFuncName = " _WD_FrameEnter"
553
- Local Const $sParameters = ' Parameters: Identifier=' & $vIdentifier
554
- Local $sOption , $sValue , $sResponse , $oJSON
558
+ If String ($vIdentifier ) = ' null' Then $vIdentifier = Null ; String must be used because checking 0 = 'null' is True
559
+ Local Const $bIsIdentifierNull = (IsKeyword ($vIdentifier ) = $KEYWORD_NULL )
560
+ Local Const $sParameters = ' Parameters: Identifier=' & ($bIsIdentifierNull ? (" Null" ) : ($vIdentifier ))
561
+ Local $sValue , $sMessage = ' ' , $sOption , $sResponse , $oJSON
555
562
Local $iErr = $_WD_ERROR_Success
556
563
557
- ; *** Encapsulate the value if it's an integer, assuming that it's supposed to be an Index, not ID attrib value.
558
- If (IsKeyword ($vIdentifier ) = $KEYWORD_NULL ) Then
564
+ ; must start with null or digit, must have at least one slash (may have many slashes but should not be followed one per other), must end with digit
565
+ Local Const $bIdentifierAsPath = StringRegExp ($vIdentifier , " (?i)\A(?:Null|\d+)(?:\/\d+)+\Z" , $STR_REGEXPMATCH )
566
+
567
+ If $bIdentifierAsPath Then
568
+ ; will be processed below
569
+ ElseIf $bIsIdentifierNull Then
559
570
$sOption = ' {"id":null}'
560
571
ElseIf IsInt ($vIdentifier ) Then
561
572
$sOption = ' {"id":' & $vIdentifier & ' }'
562
573
Else
563
- $sOption = ' {"id":' & __WD_JsonElement($vIdentifier ) & ' }'
574
+ _WinAPI_GUIDFromString(" {" & $vIdentifier & " }" )
575
+ If @error Then
576
+ $iErr = $_WD_ERROR_InvalidArgue
577
+ Else
578
+ $sOption = ' {"id":' & __WD_JsonElement($vIdentifier ) & ' }'
579
+ EndIf
564
580
EndIf
565
581
566
- $sResponse = _WD_Window($sSession , " frame" , $sOption )
582
+ If $iErr = $_WD_ERROR_Success Then ; check if $vIdentifier was succesfully validated
583
+ If Not $bIdentifierAsPath Then
584
+ $sResponse = _WD_Window($sSession , " frame" , $sOption )
585
+ $iErr = @error
586
+ Else
587
+ Local $aIdentifiers = StringSplit ($vIdentifier , ' /' )
588
+ For $i = 1 To $aIdentifiers [0 ]
589
+ If String ($aIdentifiers [$i ]) = ' null' Then
590
+ $aIdentifiers [$i ] = ' {"id":null}'
591
+ Else
592
+ $aIdentifiers [$i ] = ' {"id":' & $aIdentifiers [$i ] & ' }'
593
+ EndIf
594
+ $sResponse = _WD_Window($sSession , " frame" , $aIdentifiers [$i ])
595
+ If Not @error Then ContinueLoop
596
+
597
+ $iErr = @error
598
+ $sMessage = ' Error on ID#' & $i & ' > ' & $aIdentifiers [$i ]
599
+ ExitLoop
600
+ Next
601
+ EndIf
602
+ EndIf
567
603
568
- If @error <> $_WD_ERROR_Success Then
569
- $iErr = $_WD_ERROR_Exception
570
- Else
604
+ If $iErr = $_WD_ERROR_Success Then
571
605
$oJSON = Json_Decode($sResponse )
572
606
$sValue = Json_Get($oJSON , $_WD_JSON_Value )
573
607
@@ -577,9 +611,11 @@ Func _WD_FrameEnter($sSession, $vIdentifier)
577
611
Else
578
612
$sValue = True
579
613
EndIf
614
+ ElseIf $iErr <> $_WD_ERROR_InvalidArgue Then
615
+ $iErr = $_WD_ERROR_Exception
580
616
EndIf
581
617
582
- Return SetError (__WD_Error($sFuncName , $iErr , $sParameters ), 0 , $sValue )
618
+ Return SetError (__WD_Error($sFuncName , $iErr , $sParameters & $sMessage ), 0 , $sValue )
583
619
EndFunc ; ==>_WD_FrameEnter
584
620
585
621
; #FUNCTION# ====================================================================================================================
0 commit comments