au3WebDriver icon indicating copy to clipboard operation
au3WebDriver copied to clipboard

_WD_GetElementFromPoint + _WD_FrameEnter usage

Open mlipok opened this issue 2 years ago • 5 comments

Bug report

Describe the bug

_WD_GetElementFromPoint may affect script as it uses _WD_FrameEnter to change frames

How to reproduce

WIP (so far it only points to a possible problem - i think this need more investigation)

Expected behavior

any UDF function which internally is using _WD_FrameEnter to change frames, should back to calling frame.

Screenshots

WIP

Additional context

My intention is to follow your suggestion from here: https://github.com/Danp2/au3WebDriver/pull/362#issuecomment-1204041883

https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint

System under test

not related

mlipok avatar Aug 06 '22 19:08 mlipok

any UDF function which internally is using _WD_FrameEnter to change frames, should back to calling frame.

Not true in this case because _WD_GetElementFromPoint returns an Element ID that is only valid from within the correct browsing context. AFAIK, you won't be able to interact with or perform any actions on the found element if you automatically return to the prior browsing context.

If you read the remarks in the header, you'll see that the function sets the value of @extended if the browsing context was changed. The calling script should save / restore the browsing context if needed.

Danp2 avatar Aug 06 '22 21:08 Danp2

hm.... interesting

this following part

Local $sScript1 = "return document.elementFromPoint(arguments[0], arguments[1]);"
...
$sElement = _WD_ExecuteScript($sSession, $sScript1, $sParams, Default, $_WD_JSON_Element)

can return any element even <div> . Additionally it return such element even when there is no frames and only top level document.

So why it is fired:

_WD_FrameEnter($sSession, $sElement)
$iFrame = 1

at least why $iFrame = 1 when there is only one top level document ?

mlipok avatar Aug 06 '22 22:08 mlipok

IDK. The code should have exited prior to that point if there wasn't a frame involved. It shouldn't be too difficult for you to debug. 😃

Danp2 avatar Aug 06 '22 22:08 Danp2

I will test ASAP.

mlipok avatar Aug 06 '22 22:08 mlipok

You can assign this to me.

mlipok avatar Aug 24 '22 22:08 mlipok

@mlipok Are you still looking into this or can we close it?

Danp2 avatar Feb 22 '23 15:02 Danp2

give some more time. Max 2 weeks

mlipok avatar Feb 22 '23 16:02 mlipok

@mlipok Any update?

P.S. Shouldn't this line be checking for "frame" instead of "iframe" so that both element types are detected? That's the only reason to use StringInStr, correct?

https://github.com/Danp2/au3WebDriver/blob/951ace1473b2c1724ce9b116ef6cb455cc064b66/wd_helper.au3#L554

Danp2 avatar Mar 28 '23 16:03 Danp2

Lets stick to current Pull Request. When we accompilish PR's then I review issues and start working on them.

mlipok avatar Mar 29 '23 19:03 mlipok

I use: https://stackoverflow.com/a/34348306/5314940

onmousemove = function(e){console.log("mouse location:", e.clientX, e.clientY)}

to track mouse and start testing this issue

mlipok avatar Apr 04 '23 07:04 mlipok

@mlipok Any update?

P.S. Shouldn't this line be checking for "frame" instead of "iframe" so that both element types are detected? That's the only reason to use StringInStr, correct?

https://github.com/Danp2/au3WebDriver/blob/951ace1473b2c1724ce9b116ef6cb455cc064b66/wd_helper.au3#L554

yes Please take a look on: https://github.com/Danp2/au3WebDriver/pull/450

mlipok avatar Apr 04 '23 09:04 mlipok

Expected behavior

any UDF function which internally is using _WD_FrameEnter to change frames, should back to calling frame.

this is still valid

mlipok avatar Apr 04 '23 09:04 mlipok

I mean that we should add option to

  1. automatically get _WD_FrameList()
  2. check which Frame is active (before _WD_FrameEnter)
  3. back to back to the same Frame (on function Exit)

mlipok avatar Apr 04 '23 11:04 mlipok

This could be done, but there are a few problems with your suggestion --

  • IMO using _WD_FrameList would be overkill.
  • It would also create the scenario described above
  • It would require the function to also return the frame's Element ID, which would be used to switch back to the correct browsing context for the Element ID found by this function.

I may have a solution for the above.

Danp2 avatar Apr 04 '23 13:04 Danp2

@mlipok See https://github.com/Danp2/au3WebDriver/pull/451. Untested thus far so YMMV. 😉

Danp2 avatar Apr 04 '23 13:04 Danp2

I see getcontext But how to set or switch to desired context ?

mlipok avatar Apr 04 '23 14:04 mlipok

_WD_FrameEnter was my initial thought, but I see this would only work with frames at the current level.

Wouldn't your solution require multiple calls to _WD_FrameList (once before determining the element from point and once after determining the element from point)?

Edit: After some testing, I see that _WD_FrameList would only need to be called once.

Danp2 avatar Apr 04 '23 14:04 Danp2

@mlipok Were you ever able to reproduce this issue?

Edit: Or is that what you are looking at here?

Danp2 avatar Apr 04 '23 15:04 Danp2

@mlipok Any feedback on the above?

Danp2 avatar Apr 21 '23 11:04 Danp2

ASAP, keep waiting.

mlipok avatar Apr 21 '23 11:04 mlipok

@mlipok I've fixed a few issues with _WD_GetElementFromPoint in #478, but I haven't been able to reproduce your scenario where $iFrame = 1 when there aren't any frames. My plan is to close this issue unless you can provide a reproducer.

Danp2 avatar May 27 '23 20:05 Danp2

unless you can provide a reproducer.

Asap, few days

mlipok avatar May 27 '23 23:05 mlipok

We can reopen if you can reproduce.

Danp2 avatar May 31 '23 13:05 Danp2

Recently we did some new findings/modifications here: https://github.com/Danp2/au3WebDriver/pull/490 and here: https://github.com/Danp2/au3WebDriver/issues/488

Is this somehow related ?

mlipok avatar Aug 17 '23 08:08 mlipok

Not AFAIK.

Danp2 avatar Aug 17 '23 12:08 Danp2