Skip to content

Commit 114edc7

Browse files
authored
Fix _WD_GetElementFromPoint (#478)
1 parent e2edb4e commit 114edc7

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
Go to [legend](#legend---types-of-changes) for further information about the types of changes.
1111

12+
## [Unreleased]
13+
14+
### Fixed
15+
16+
- _WD_GetElementFromPoint
17+
- Correct frame identification
18+
- Handle Null result from `document.elementFromPoint`
19+
1220
## [1.0.2] 2023-05-24
1321

1422
### Fixed

wd_helper.au3

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -611,41 +611,56 @@ EndFunc ;==>_WD_GetMouseElement
611611
Func _WD_GetElementFromPoint($sSession, $iX, $iY)
612612
Local Const $sFuncName = "_WD_GetElementFromPoint"
613613
Local Const $sParameters = 'Parameters: X=' & $iX & ' Y=' & $iY
614-
Local $sElement, $sTagName, $sParams, $aCoords, $iFrame = 0, $oERect
614+
Local $sResponse, $oJSON, $sElement = ""
615+
Local $sTagName, $sParams, $aCoords, $iFrame = 0, $oERect
615616
Local $sScript1 = "return document.elementFromPoint(arguments[0], arguments[1]);"
616617
Local $sScript2 = "return new Array(window.pageXOffset, window.pageYOffset);"
617-
Local $iErr = $_WD_ERROR_Success
618+
Local $iErr = $_WD_ERROR_Success, $sResult, $bIsNull
618619

619620
While True
620621
$sParams = $iX & ", " & $iY
621-
$sElement = _WD_ExecuteScript($sSession, $sScript1, $sParams, Default, $_WD_JSON_Element)
622+
$sResponse = _WD_ExecuteScript($sSession, $sScript1, $sParams)
622623
If @error Then
623624
$iErr = $_WD_ERROR_RetValue
624625
ExitLoop
625626
EndIf
626627

627-
$sTagName = _WD_ElementAction($sSession, $sElement, "Name")
628-
If Not StringInStr("frame", $sTagName) Then ; check <iframe> and <frame> element
629-
ExitLoop
630-
EndIf
628+
$oJSON = Json_Decode($sResponse)
629+
$sElement = Json_Get($oJSON, $_WD_JSON_Element)
631630

632-
$aCoords = _WD_ExecuteScript($sSession, $sScript2, $_WD_EmptyDict, Default, $_WD_JSON_Value)
633631
If @error Then
634-
$iErr = $_WD_ERROR_RetValue
632+
$sResult = Json_Get($oJSON, $_WD_JSON_Value)
633+
$bIsNull = (IsKeyword($sResult) = $KEYWORD_NULL)
634+
635+
If Not $bIsNull Then
636+
$iErr = $_WD_ERROR_RetValue
637+
EndIf
638+
635639
ExitLoop
636-
EndIf
640+
Else
641+
$sTagName = _WD_ElementAction($sSession, $sElement, "Name")
642+
If Not StringInStr($sTagName, "frame") Then ; check <iframe> and <frame> element
643+
ExitLoop
644+
EndIf
645+
646+
$aCoords = _WD_ExecuteScript($sSession, $sScript2, $_WD_EmptyDict, Default, $_WD_JSON_Value)
647+
If @error Then
648+
$iErr = $_WD_ERROR_RetValue
649+
ExitLoop
650+
EndIf
637651

638-
$oERect = _WD_ElementAction($sSession, $sElement, 'rect')
652+
$oERect = _WD_ElementAction($sSession, $sElement, 'rect')
639653

640-
; changing the coordinates in relation to left top corner of frame
641-
$iX -= ($oERect.Item('x') - Int($aCoords[0]))
642-
$iY -= ($oERect.Item('y') - Int($aCoords[1]))
654+
; changing the coordinates in relation to left top corner of frame
655+
$iX -= ($oERect.Item('x') - Int($aCoords[0]))
656+
$iY -= ($oERect.Item('y') - Int($aCoords[1]))
643657

644-
_WD_FrameEnter($sSession, $sElement)
645-
$iFrame = 1
658+
_WD_FrameEnter($sSession, $sElement)
659+
$iFrame = 1
660+
EndIf
646661
WEnd
647662

648-
Return SetError(__WD_Error($sFuncName, $iErr, $sParameters), $iFrame, $sElement)
663+
Return SetError(__WD_Error($sFuncName, $iErr, $sParameters, $iFrame), $iFrame, $sElement)
649664
EndFunc ;==>_WD_GetElementFromPoint
650665

651666
; #FUNCTION# ====================================================================================================================
@@ -1942,7 +1957,7 @@ EndFunc ;==>_WD_GetShadowRoot
19421957
Func _WD_SelectFiles($sSession, $sStrategy, $sSelector, $sFilename)
19431958
Local Const $sFuncName = "_WD_SelectFiles"
19441959
Local Const $sParameters = 'Parameters: Strategy=' & $sStrategy & ' Selector=' & $sSelector & ' Filename=' & $sFilename
1945-
Local $sResult = "0", $sSavedEscape
1960+
Local $sResult = "0"
19461961
Local $sElement = _WD_FindElement($sSession, $sStrategy, $sSelector)
19471962
Local $iErr = @error
19481963

0 commit comments

Comments
 (0)