@@ -980,7 +980,7 @@ EndFunc ;==>_WD_ElementOptionSelect
980
980
; $sSelectElement - Element ID of Select element from _WD_FindElement
981
981
; $sCommand - Action to be performed. Can be one of the following:
982
982
; |OPTIONS - Retrieve array containing value / label attributes from the Select element's options
983
- ; |VALUE - Retrieve current value
983
+ ; |VALUE - Retrieve current value
984
984
; Return values .: Success - Requested data returned by web driver.
985
985
; Failure - "" (empty string) and sets @error to one of the following values:
986
986
; - $_WD_ERROR_NoMatch
@@ -997,44 +997,37 @@ EndFunc ;==>_WD_ElementOptionSelect
997
997
; ===============================================================================================================================
998
998
Func _WD_ElementSelectAction($sSession , $sSelectElement , $sCommand )
999
999
Local Const $sFuncName = " _WD_ElementSelectAction"
1000
- Local $sNodeName , $sJsonElement , $vResult
1001
- Local $sText , $aOptions
1000
+ Local $sNodeName , $vResult
1002
1001
1003
1002
$sNodeName = _WD_ElementAction($sSession , $sSelectElement , ' property' , ' nodeName' )
1004
1003
Local $iErr = @error
1005
1004
1006
- If $iErr = $_WD_ERROR_Success And $sNodeName = ' select' Then
1007
-
1008
- Switch $sCommand
1009
- Case ' value'
1010
- ; Retrieve current value of designated Select element
1011
- $sJsonElement = __WD_JsonElement($sSelectElement )
1012
- $vResult = _WD_ExecuteScript($sSession , " return arguments[0].value" , $sJsonElement , Default , $_WD_JSON_Value )
1013
- $iErr = @error
1014
-
1015
- Case ' options'
1016
- ; Retrieve array containing value / label attributes from the Select element's options
1017
- $aOptions = _WD_FindElement($sSession , $_WD_LOCATOR_ByXPath , " ./option" , $sSelectElement , True )
1018
- $iErr = @error
1019
-
1020
- If $iErr = $_WD_ERROR_Success Then
1021
- $sText = " "
1022
- For $sElement In $aOptions
1023
- $sJsonElement = __WD_JsonElement($sElement )
1024
- $sText &= (($sText <> " " ) ? @CRLF : " " ) & _WD_ExecuteScript($sSession , " return arguments[0].value + '|' + arguments[0].label" , $sJsonElement , Default , $_WD_JSON_Value )
1025
- $iErr = @error
1026
- Next
1027
-
1028
- Local $aOut [0 ][2 ]
1029
- _ArrayAdd($aOut , $sText , 0 , Default , @CRLF , 1 )
1030
- $vResult = $aOut
1031
- EndIf
1032
- Case Else
1033
- Return SetError (__WD_Error($sFuncName , $_WD_ERROR_InvalidDataType , " (Value|Options) $sCommand=>" & $sCommand ), 0 , " " )
1005
+ If $iErr = $_WD_ERROR_Success Then
1006
+ If $sNodeName = ' select' Then
1007
+ Switch $sCommand
1008
+ Case ' value'
1009
+ ; Retrieve current value of designated Select element
1010
+ $vResult = _WD_ExecuteScript($sSession , " return arguments[0].value" , __WD_JsonElement($sSelectElement ), Default , $_WD_JSON_Value )
1011
+ $iErr = @error
1012
+
1013
+ Case ' options'
1014
+ ; Retrieve array containing value / label attributes from the Select element's options
1015
+ Local $sScript = " var result =''; var options = arguments[0].options; for (let i = 0; i < options.length; i++) {result += options[i].value + '|' + options[i].label + '\n'} return result;"
1016
+ $vResult = _WD_ExecuteScript($sSession , $sScript , __WD_JsonElement($sSelectElement ), Default , $_WD_JSON_Value )
1017
+ $iErr = @error
1018
+ If $iErr = $_WD_ERROR_Success Then
1019
+ Local $sText = StringStripWS ($vResult , $STR_STRIPTRAILING )
1020
+ Local $aOut [0 ][2 ]
1021
+ _ArrayAdd($aOut , $sText , 0 , Default , @LF , 1 )
1022
+ $vResult = $aOut
1023
+ EndIf
1024
+ Case Else
1025
+ Return SetError (__WD_Error($sFuncName , $_WD_ERROR_InvalidDataType , " (Value|Options) $sCommand=>" & $sCommand ), 0 , " " )
1034
1026
1035
- EndSwitch
1036
- Else
1037
- $iErr = $_WD_ERROR_InvalidArgue
1027
+ EndSwitch
1028
+ Else
1029
+ $iErr = $_WD_ERROR_InvalidArgue
1030
+ EndIf
1038
1031
EndIf
1039
1032
1040
1033
If $_WD_DEBUG = $_WD_DEBUG_Info Then
0 commit comments