Danp2 / au3WebDriver

Web Driver UDF for AutoIt
MIT License
108 stars 23 forks source link

_WD_ElementActionEx fails if element isn't visible in viewport #403

Closed Danp2 closed 1 year ago

Danp2 commented 1 year ago

Bug report

Describe the bug

_WD_ElementActionEx doesn't scroll the target element into view, which can lead to failure of some webdriver actions.

How to reproduce

Run the following in wd_demo's UserTesting function --

Func UserTesting() ; here you can replace the code to test your stuff before you ask on the forum
    Local $sURL = "https://about.google/"
    Local $sXpath = "(//a[normalize-space()='View all our commitments'])[1]"

    _WD_Navigate ($sSession, $sURL)
    _WD_LoadWait ($sSession)

    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $sXpath)
    _WD_ElementActionEx($sSession, $sElement, "hover")
EndFunc   ;==>UserTesting

Here's the corresponding logs --

    __WD_Post: URL=HTTP://127.0.0.1:4444/session/1be1e01e-0774-40c8-b116-bb7e3c686e3d/actions; Data={"actions":[{"id":"hover","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"type":"pointerMove","duration":100,"x":0,"y":0,"origin":{"ELEMENT":"dd776eaa-a915-4332-b3ca-532985074fe3","element-6066-11e4-a52e-4f735466cecf":"dd776eaa-a915-4332-b3ca-532985074fe3"}}]}]}
    __WD_Post ==> Webdriver Exception [10] : HTTP status = 500 ResponseText={"value":{"error":"move target out of bounds","message":"(640, 1979) is out of bounds of viewport width (1282) and height (982)","stacktrace":"RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8\nWebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:182:5\nMoveTargetOutOfBoundsError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:372:5\nassertInViewPort@chrome://remote/content/marionette/action.sys.mjs:2113:11\ndispatch@chrome://remote/content/marionette/action.sys.mjs:1011:21\ndispatch/pendingEvents<@chrome://remote/content/marionette/action.sys.mjs:1827:14\ndispatch@chrome://remote/content/marionette/action.sys.mjs:1826:39\ndispatch/chainEvents<@chrome://remote/content/marionette/action.sys.mjs:1753:27\ndispatch@chrome://remote/content/marionette/action.sys.mjs:1755:7\nperformActions@chrome://remote/content/marionette/actors/MarionetteCommandsChild.sys.mjs:472:23\nreceiveMessage@chrome://remote/content/marionette/actors/MarionetteCommandsChild.sys.mjs:139:31\n"}}
    _WD_Action ==> Webdriver Exception [10] : Parameters:   Command=actions   Option={"actions":[{"id":"hover","type":"pointer","parameters":{"pointerType":"mouse"},"actions":[{"type":"pointerMove","duration":100,"x":0,"y":0,"origin":{"ELEMENT":"dd776eaa-a915-4332-b3ca-532985074fe3","element-6066-11e4-a52e-4f735466cecf":"dd776eaa-a915-4332-b3ca-532985074fe3"}}]}]}
    _WD_ElementActionEx ==> Webdriver Exception [10] : Parameters:    Element=dd776eaa-a915-4332-b3ca-532985074fe3    Command=hover    XOffset=Default    YOffset=Default    Button=Default    HoldDelay=Default    Modifier=Default

Expected behavior

Element to be scrolled into view as needed and mouse to hover over the target element

Additional context

https://github.com/w3c/webdriver/issues/1005

Danp2 commented 1 year ago

Until there is Scroll Into View support for Actions, the easiest way to resolve this is with Javascript --

_WD_ExecuteScript($sSession, "arguments[0].scrollIntoView(false);", __WD_JsonElement($sElement))
Sleep(500)

The short sleep is to allow time for the window to scroll before continuing. I was able to scroll the browser window with Wheel actions, but attempts to scroll in relation to the target element failed --

{"actions":[{"id":"scroll","type":"wheel","actions":[{"type":"scroll", "duration":100,"x":0,"y":0, "deltaX":0, "deltaY":0, "origin":{"ELEMENT":"dd776eaa-a915-4332-b3ca-532985074fe3","element-6066-11e4-a52e-4f735466cecf":"dd776eaa-a915-4332-b3ca-532985074fe3"}}]}]}

resulted in this --

{ "value": { "error": "move target out of bounds", "message": "(640, 1854) is out of bounds of viewport width (1282) and height (982)", "stacktrace": "RemoteError@chrome://remote/content/shared/RemoteError.sys.mjs:8:8\nWebDriverError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:182:5\nMoveTargetOutOfBoundsError@chrome://remote/content/shared/webdriver/Errors.sys.mjs:372:5\nassertInViewPort@chrome://remote/content/marionette/action.sys.mjs:2113:11\ndispatch@chrome://remote/content/marionette/action.sys.mjs:1149:21\ndispatch/pendingEvents<@chrome://remote/content/marionette/action.sys.mjs:1827:14\ndispatch@chrome://remote/content/marionette/action.sys.mjs:1826:39\ndispatch/chainEvents<@chrome://remote/content/marionette/action.sys.mjs:1753:27\ndispatch@chrome://remote/content/marionette/action.sys.mjs:1755:7\nperformActions@chrome://remote/content/marionette/actors/MarionetteCommandsChild.sys.mjs:472:23\nreceiveMessage@chrome://remote/content/marionette/actors/MarionetteCommandsChild.sys.mjs:139:31\n" } }

mlipok commented 1 year ago

@Danp2 was there discussion on Au3Forum ? Did I made an bypass fix for this ? Can you point here this discussion and my fix ?

Danp2 commented 1 year ago

There was related discussion in #402. Perhaps that is what you remember?