MCPcopy Create free account
hub / github.com/PageBot/PageBot / getElementByName

Method getElementByName

Lib/pagebot/elements/element.py:679–706  ·  view source on GitHub ↗

Answers the first element in the offspring list that fits the name. Answers None if it cannot be found. Note that the result of the search depends on where in the tree self is. If self.isPage there probably is a different set of elements found than searching witn sel

(self, name)

Source from the content-addressed store, hash-verified

677 return None
678
679 def getElementByName(self, name):
680 """Answers the first element in the offspring list that fits the name.
681 Answers None if it cannot be found.
682
683 Note that the result of the search depends on where in the tree self is.
684 If self.isPage there probably is a different set of elements found than
685 searching witn self as arbitrary Element instance.
686
687 >>> e1 = Element(name='Deeper')
688 >>> e2 = Element(name='Deeper')
689 >>> e3 = Element(name='Child', elements=[e1, e2])
690 >>> e = Element(name='Parent', elements=[e3])
691 >>> # Get child element by its name
692 >>> child = e.get('Child')
693 >>> child is e3
694 True
695 >>> # Find first down the list
696 >>> e.get('Deeper') is e1, e.get('Deeper') is e2
697 (True, False)
698 """
699 if self.name == name:
700 return self
701 for e in self.elements:
702 # Don't search on next page yet.
703 found = e.getElementByName(name)
704 if found is not None:
705 return found
706 return None
707
708 # D R A W B O T / F L A T S U P P O R T
709

Callers 3

getMethod · 0.95
overflow2NextMethod · 0.80
overflow2NextMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected