Menu

#1648 Wrong activeElement for iFrames and their parents

Latest SVN
closed
RBRi
None
1
2014-10-18
2014-10-17
Carsten
No

We have found two issues with document.activeElement if iframes are used.

First: When setting the focus on an element in an iframe the document.activeElement of the parentWindow ist still the body, but
in FF it is set to the iframe element.

Second one is a bit more complicated.
HTMLIFrameElement.getContentWindow() returns a Window and not a WindowProxy like HTMLFrameElement does.
So calling something like Object(iFrameElement.contentWindow) causes iFrameWindow.parentScope to be set to the parentWindow.
This in turn means that when HtmlElement.setActive() for any element in the iFrameWindow is called it sets parentWindow.document.activeElement instead of frameWindow.document.activeElement.
When now WebClient.setCurrentWindow(parentWindow) is called it gets the wrong activeElement and calls HtmlPage.setFocusedElement() with it leading to the exception below.

java.lang.IllegalArgumentException: Can't move focus to an element from a different page.
at com.gargoylesoftware.htmlunit.html.HtmlPage.setFocusedElement(HtmlPage.java:2047)
at com.gargoylesoftware.htmlunit.WebClient.setCurrentWindow(WebClient.java:743)
at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1238)
at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1216)

A patch with a test case and possible fix for the second problem is attached. The test is primarily for the second problem but it also shows the first one when executed with a real browser. I ran all tests with the patch and now 6 tests in JQuery182Test annotated with @NotYetImplemented throw an exception that they work.
I am not sure if they really do so I have not changed anything there.

1 Attachments

Discussion

  • RBRi

    RBRi - 2014-10-17

    Sounds interesting and some gone NYI will be great.
    Will have a look later....

     
  • RBRi

    RBRi - 2014-10-18
    • status: open --> accepted
    • assigned_to: RBRi
     
  • RBRi

    RBRi - 2014-10-18

    Thanks a lot for the report/patch.

     
  • RBRi

    RBRi - 2014-10-18
    • status: accepted --> closed
     

Log in to post a comment.