Get an item within this element. Behaviour depends on the key type: - Integer: returns the child at that index. - Slice: returns a collection of children in that slice. - String: looks up an element by id (with or without '#' prefix). ```python
(self, key)
| 495 | return isinstance(obj, Element) and obj._dom_element == self._dom_element |
| 496 | |
| 497 | def __getitem__(self, key): |
| 498 | """ |
| 499 | Get an item within this element. |
| 500 | |
| 501 | Behaviour depends on the key type: |
| 502 | |
| 503 | - Integer: returns the child at that index. |
| 504 | - Slice: returns a collection of children in that slice. |
| 505 | - String: looks up an element by id (with or without '#' prefix). |
| 506 | |
| 507 | ```python |
| 508 | element[0] # First child. |
| 509 | element[1:3] # Second and third children. |
| 510 | element["my-id"] # Element with id="my-id" (or None). |
| 511 | element["#my-id"] # Same as above (# is optional). |
| 512 | ``` |
| 513 | """ |
| 514 | |
| 515 | if isinstance(key, (int, slice)): |
| 516 | return self.children[key] |
| 517 | if isinstance(key, str): |
| 518 | return _find_by_id(self._dom_element, key) |
| 519 | raise TypeError( |
| 520 | f"Element indices must be integers, slices, or strings, " |
| 521 | f"not {type(key).__name__}." |
| 522 | ) |
| 523 | |
| 524 | def __getattr__(self, name): |
| 525 | """ |
nothing calls this directly
no test coverage detected