You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ArrayHandle null trying to enumerate <li/> menu items #54
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.publicasyncTask<T[]>QuerySelectorAllAsync<T>(stringselector)whereT:Element{vararrayHandle=awaitEvaluateFunctionHandleInternalAsync<DomHandle>("(element, selector) => element.querySelectorAll(selector)",selector).ConfigureAwait(false);// AH is null:varproperties=awaitarrayHandle.GetArray<T>().ConfigureAwait(false);// ^^^^^^^^^^^awaitarrayHandle.DisposeAsync().ConfigureAwait(false);returnproperties.ToArray();}
In my calling code:
// Selector "#menu", does return a valid element construct, AFAIK from debug inspection:varulMenu=awaitcontext.QuerySelectorAsync<HtmlUnorderedListElement>(S.Menu);// Selector "li", null ref exception thrown from within, expecting HtmlListItemElement[].varliCandidates=awaitulMenu.QuerySelectorAllAsync<HtmlListItemElement>(S.Li);// Will turn around and LINQ filter based on some other criteria, but not getting anywhere near that far.varliServerItems=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:
And it "works". Sort it, but it will not work for us, I think, because these are "all" of the <li/>, not just the ones subordinate to the ulMenu that we want.
Maybe there is a better way to get those children, I do not know.
Note that the <li/> children are not all flat; it would be considered best for a depth first recursive search. I'm assuming that's how the console does it, but I could be mistaken.
After poking around a bit and exploring the query and child paths available, this one will work, and I rather prefer it actually. Seems to be focused on the direct child elements of the specified type, which is perfect, just what we need. Not that the other one ought not to work, in principle, but this one does as well, FWIW.
varulMenu=awaitcontext.QuerySelectorAsync<HtmlUnorderedListElement>(S.Menu);varliServerItems=await(awaitulMenu.GetChildrenAsync<HtmlListItemElement>()).ToArrayAsync();// ...and on from there, drilled through a couple other use cases, including another nested <li/>, also successfully.
The only thing I dislike about it, the lack of selector comprehension, in the event we need to provide more discernment there, but for what we are doing, I think it will be sufficient.
And it "works". Sort it, but it will not work for us, I think, because these are "all" of the <li/>, not just the ones subordinate to the ulMenu that we want.
Maybe there is a better way to get those children, I do not know.
You know querySelectorAll supports css selectors? You should be able to make a single querySelectorAll call
Activity
mwpowellhtx commentedon Jul 8, 2024
Another data point for you, for giggles I tried the following.
And it "works". Sort it, but it will not work for us, I think, because these are "all" of the
<li/>, not just the ones subordinate to theulMenuthat we want.Maybe there is a better way to get those children, I do not know.
mwpowellhtx commentedon Jul 8, 2024
Note that the
<li/>children are not all flat; it would be considered best for a depth first recursive search. I'm assuming that's how the console does it, but I could be mistaken.mwpowellhtx commentedon Jul 8, 2024
After poking around a bit and exploring the query and child paths available, this one will work, and I rather prefer it actually. Seems to be focused on the direct child elements of the specified type, which is perfect, just what we need. Not that the other one ought not to work, in principle, but this one does as well, FWIW.
The only thing I dislike about it, the lack of selector comprehension, in the event we need to provide more discernment there, but for what we are doing, I think it will be sufficient.
amaitland commentedon Jul 12, 2024
Your code looks fine, likely it's a bug.
querySelectorAllreturns aNodeListand there's currently no mapping for that yet.The other
QuerySelectorAllAsyncmethods do something slightly different. Something like the following should work.You know
querySelectorAllsupports css selectors? You should be able to make a singlequerySelectorAllcallmwpowellhtx commentedon Jul 12, 2024
Awesome; duly noted, for future reference. Thank you... 🍻
amaitland commentedon Jul 12, 2024
We should fix the current implementation.
mwpowellhtx commentedon Jul 12, 2024
Cool. That'd be great, overall in general.
Although, I do have a workaround, which I think is a bit better suited to the target DOM in question.