Skip to content

Finding an element by id in ElementCollection does not always work. #2467

@ntoll

Description

@ntoll

Checklist

  • I added a descriptive title
  • I searched for other issues and couldn't find a solution or duplication
  • I already searched in Google and didn't find any good information or help

What happened?

Discord user "h" reported this problem via this project:

https://pyscript.com/@serialcomma/steep-art-copy/latest?files=main.py

In an ElementCollection, which is what items is here:

items = web.page.find("li")

You get a collection of li elements.

But you may not get the matching li element if you do this:

my_li = items["#an-id"]

The bug is that the id is checked in the children of those contained elements, not the id of the (li) elements themselves, in this case. If an li has the id of #an-id then it is missed since only its children are used to match the query.

What browsers are you seeing the problem on? (if applicable)

No response

Console info

Additional Context

No response

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions