Menu ▾ ▴

#1849 SgmlPage.getElementsByTagName("*") does not return all DomElement descendants

2.24
closed
None
1
2017-01-11
2017-01-09
Mark Fulton
No

SgmlPage.getElementsByTagName("*") should return the same logic collection as SgmlPage.getDomElementDescendants() but it returns an empty collection instead.

Discussion

  • Ahmed Ashour

    Ahmed Ashour - 2017-01-10
    • status: open --> pending
    • assigned_to: Ahmed Ashour
     
  • Ahmed Ashour

    Ahmed Ashour - 2017-01-10

    Well, doing this fails DomNodeListTest.getElementsByTagName(), HtmlForm2Test.base(), HtmlElementTest.getElementsByTagName2() and HtmlPageTest.getElementsByTagName().

    Please provide a test case that shows the current logic is incorrect.

     
  • Mark Fulton

    Mark Fulton - 2017-01-10

    Here is a test case for DomNodeLIstTest:

        /**
    
         * @throws Exception if the test fails
         */
        @Test
        public void getAllElementsBySpecialTagNameValue() throws Exception {
            final String firstContent
                = "<html><head><title>First</title></head>\n"
                + "<body>\n"
                + "<form><input type='button' name='button1' value='pushme'></form>\n"
                + "<div>a</div> <div>b</div> <div>c</div>\n"
                + "</body></html>";
    
            final HtmlPage page = loadPage(firstContent);
    
            final DomNodeList<DomElement> elements = page.getElementsByTagName("*");
    
            assertEquals(9, elements.getLength());
            validateDomNodeList(elements);
    
            final HtmlDivision newDiv = new HtmlDivision(HtmlDivision.TAG_NAME, page, null);
            page.getBody().appendChild(newDiv);
            assertEquals(10, elements.getLength());
            validateDomNodeList(elements);
        }
    

    And here is what I inserted at the beginning of SgmlPage.getElementsByTagName(String) to get the test to pass:

            if ("*".equals(tagName)) {
                return new AbstractDomNodeList<DomElement>(this) {
                    @Override
                    protected List<DomElement> provideElements() {
                        final List<DomElement> res = new LinkedList<>();
                        for (final DomElement elem : getDomElementDescendants()) {
                            res.add(elem);
                        }
                        return res;
                    }
                };
            }
    
     
  • Ahmed Ashour

    Ahmed Ashour - 2017-01-10
    • status: pending --> closed
     
  • Ahmed Ashour

    Ahmed Ashour - 2017-01-10

    Thanks for reporting and the test case. Now I understand the '*'.

    Fixed in SVN.

     
  • Mark Fulton

    Mark Fulton - 2017-01-10

    Oh, I just realized that the same should be applied to getElementsByTagNameNS...

     
  • Ahmed Ashour

    Ahmed Ashour - 2017-01-10
    • status: closed --> accepted
     
  • Ahmed Ashour

    Ahmed Ashour - 2017-01-10

    Also Element.getElementsByTagNameNS needs to be modified.

     
  • Ahmed Ashour

    Ahmed Ashour - 2017-01-11
    • status: accepted --> closed
     
  • Ahmed Ashour

    Ahmed Ashour - 2017-01-11

    Thanks for the feedback, fixed in SVN.

     

Log in to post a comment.