Skip to content

Commit 77a2aa1

Browse files
authored
_WD_ElementActionEx: Scroll element into view by default (#411)
1 parent c30c071 commit 77a2aa1

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

wd_helper.au3

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2400,7 +2400,7 @@ EndFunc ;==>_WD_SetElementValue
24002400
; #FUNCTION# ====================================================================================================================
24012401
; Name ..........: _WD_ElementActionEx
24022402
; Description ...: Perform advanced action on designated element.
2403-
; Syntax ........: _WD_ElementActionEx($sSession, $sElement, $sCommand[, $iXOffset = Default[, $iYOffset = Default[, $iButton = Default[, $iHoldDelay = Default[, $sModifier = Default]]]]])
2403+
; Syntax ........: _WD_ElementActionEx($sSession, $sElement, $sCommand[, $iXOffset = Default[, $iYOffset = Default[, $iButton = Default[, $iHoldDelay = Default[, $sModifier = Default[, $bScrollView = Default]]]]]])
24042404
; Parameters ....: $sSession - Session ID from _WD_CreateSession
24052405
; $sElement - Element ID from _WD_FindElement
24062406
; $sCommand - one of the following actions:
@@ -2416,11 +2416,12 @@ EndFunc ;==>_WD_SetElementValue
24162416
; |RIGHTCLICK - Do a rightclick on the selected element
24172417
; |SHOW - Change the element's style to 'display: normal' to unhide/show the element
24182418
; |UNCHECK - Unchecks a checkbox input element
2419-
; $iXOffset - [optional] X Offset. Default is 0
2420-
; $iYOffset - [optional] Y Offset. Default is 0
2421-
; $iButton - [optional] Mouse button. Default is $_WD_BUTTON_Left
2422-
; $iHoldDelay - [optional] Hold time in ms. Default is 1000
2423-
; $sModifier - [optional] Modifier key. Default is "\uE008" (shift key)
2419+
; $iXOffset - [optional] X Offset. Default is 0
2420+
; $iYOffset - [optional] Y Offset. Default is 0
2421+
; $iButton - [optional] Mouse button. Default is $_WD_BUTTON_Left
2422+
; $iHoldDelay - [optional] Hold time in ms. Default is 1000
2423+
; $sModifier - [optional] Modifier key. Default is "\uE008" (shift key)
2424+
; $bScrollView - [optional] Forcibly scroll element into view? Default is True
24242425
; Return values .: Success - Return value from web driver (could be an empty string)
24252426
; Failure - "" (empty string) and sets @error to one of the following values:
24262427
; - $_WD_ERROR_Exception
@@ -2433,9 +2434,9 @@ EndFunc ;==>_WD_SetElementValue
24332434
; Link ..........:
24342435
; Example .......: No
24352436
; ===============================================================================================================================
2436-
Func _WD_ElementActionEx($sSession, $sElement, $sCommand, $iXOffset = Default, $iYOffset = Default, $iButton = Default, $iHoldDelay = Default, $sModifier = Default)
2437+
Func _WD_ElementActionEx($sSession, $sElement, $sCommand, $iXOffset = Default, $iYOffset = Default, $iButton = Default, $iHoldDelay = Default, $sModifier = Default, $bScrollView = Default)
24372438
Local Const $sFuncName = "_WD_ElementActionEx"
2438-
Local Const $sParameters = 'Parameters: Element=' & $sElement & ' Command=' & $sCommand & ' XOffset=' & $iXOffset & ' YOffset=' & $iYOffset & ' Button=' & $iButton & ' HoldDelay=' & $iHoldDelay & ' Modifier=' & $sModifier
2439+
Local Const $sParameters = 'Parameters: Element=' & $sElement & ' Command=' & $sCommand & ' XOffset=' & $iXOffset & ' YOffset=' & $iYOffset & ' Button=' & $iButton & ' HoldDelay=' & $iHoldDelay & ' Modifier=' & $sModifier & ' ScrollView=' & $bScrollView
24392440
Local $sAction, $sJavascript, $iErr, $sResult, $iActionType = 1
24402441
$_WD_HTTPRESULT = 0
24412442
$_WD_HTTPRESPONSE = ''
@@ -2445,6 +2446,7 @@ Func _WD_ElementActionEx($sSession, $sElement, $sCommand, $iXOffset = Default, $
24452446
If $iButton = Default Then $iButton = $_WD_BUTTON_Left
24462447
If $iHoldDelay = Default Then $iHoldDelay = 1000
24472448
If $sModifier = Default Then $sModifier = "\uE008" ; shift
2449+
If $bScrollView = Default Then $bScrollView = True
24482450

24492451
If Not IsInt($iXOffset) Then
24502452
Return SetError(__WD_Error($sFuncName, $_WD_ERROR_InvalidDataType, "(int) $iXOffset: " & $iXOffset), 0, "")
@@ -2565,6 +2567,11 @@ Func _WD_ElementActionEx($sSession, $sElement, $sCommand, $iXOffset = Default, $
25652567
'}', @TAB, '')
25662568
#EndRegion - JSON builder
25672569

2570+
If $bScrollView Then
2571+
_WD_ExecuteScript($sSession, "arguments[0].scrollIntoView(false);", __WD_JsonElement($sElement))
2572+
Sleep(500)
2573+
EndIf
2574+
25682575
Switch $iActionType
25692576
Case 1
25702577
$sAction = StringFormat($sActionTemplate, $sPreAction, $iXOffset, $iYOffset, $sElement, $sElement, $sPostHoverAction, $sPostAction)

0 commit comments

Comments
 (0)