Skip to content

ArrayHandle null trying to enumerate <li/> menu items #54

Description

@mwpowellhtx

To frame the opportunity at hand, I tried the same thing in the Chrome dev tools in browser, and I get the range back that I am expecting.

// AH is null querying for the <li/> from the parent menu.
public async Task<T[]> QuerySelectorAllAsync<T>(string selector)
    where T : Element
{
    var arrayHandle = await EvaluateFunctionHandleInternalAsync<DomHandle>(
        "(element, selector) => element.querySelectorAll(selector)",
        selector).ConfigureAwait(false);

    // AH is null:
    var properties = await arrayHandle.GetArray<T>().ConfigureAwait(false);
    //                     ^^^^^^^^^^^
    await arrayHandle.DisposeAsync().ConfigureAwait(false);

    return properties.ToArray();
}

In my calling code:

// Selector "#menu", does return a valid element construct, AFAIK from debug inspection:
var ulMenu = await context.QuerySelectorAsync<HtmlUnorderedListElement>(S.Menu);

// Selector "li", null ref exception thrown from within, expecting HtmlListItemElement[].
var liCandidates = await ulMenu.QuerySelectorAllAsync<HtmlListItemElement>(S.Li);

// Will turn around and LINQ filter based on some other criteria, but not getting anywhere near that far.
var liServerItems = liCandidates.Where(ListItemWithImage).ToArray();
//                                     ^^^^^^^^^^^^^^^^^

I'm doing that correctly, yes? I want all the <li/> elements child to the ulMenu.
Everything else being equal, I promise you it "should be" returning valid elements, from the Chrome console:

document.querySelector("#menu").querySelectorAll("li")
// #menu: <ul class="..." id="menu" />
// li: NodeList(20) [li.mm-active, li, li, li, li, li, li, li, li, li, li, li, li, li, li, li, li, li, li, li, li]

There is obviously more within each of these elements, abbreviated for brevity.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions