Skip to content

Unable to find element using child selector '>' #24

@FrancisBaileyH

Description

@FrancisBaileyH

Firstly, let me say thanks for maintaining such a great library, it has been exceptionally useful in my project. But on to the issue

Using the following code:

$dom->find('div > ul');

Results in an empty set, despite the html being valid. It seems the find() function does not support child selectors. I added in a unit test to SelectorTest.php to confirm the results.

The test code:

    public function testFindClassWithChildSelector() {

        $root   = new HtmlNode(new Tag('root'));
        $parent = new HtmlNode(new Tag('div'));
        $child1 = new HtmlNode(new Tag('ul'));  
        $root->addChild($parent);
        $parent->addChild($child1);

        $selector = new Selector('div > ul');
        $this->assertEquals(1, count($selector->find($root)));
    }

The results:
php-html-parser-test-failed

I'm going to see if I can't add the functionality myself. However, given your familiarity with the library you may be able to make a quick change to fix this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions