timothycrosley / thedom

A python framework to generate html and JavaScript from reusable and combine-able widgets.
GNU General Public License v2.0
23 stars 6 forks source link

Bug in getChildElementWithId #3

Open triquetra011 opened 11 years ago

triquetra011 commented 11 years ago

In [88]: page = WebElements.Document.Document()

In [89]: page.body.getChildElementWithId('a')

In [90]: page += WebElements.Display.Label()

In [91]: page.body.getChildElementWithId('')

AttributeError Traceback (most recent call last)

in () ----> 1 page.body.getChildElementWithId('') /home/ego/projects/evergreen/lib/python2.7/site-packages/WebElements/Base.pyc in getChildElementWithId(self, elementId) 921 if child.id == elementId: 922 return child --> 923 nestedChild = child.getChildElementWithId(elementId) 924 if nestedChild: 925 return nestedChild /home/ego/projects/evergreen/lib/python2.7/site-packages/WebElements/Base.pyc in getChildElementWithId(self, elementId) 919 childrenWithId = None 920 for child in self: --> 921 if child.id == elementId: 922 return child 923 nestedChild = child.getChildElementWithId(elementId) AttributeError: 'TextNode' object has no attribute 'id'
triquetra011 commented 11 years ago

Easiest (not necessarily the best) solution:

WebElements/Base.py: def getChildElementWithId(self, elementId): """ Returns all elements with the id specified """ childrenWithId = None for child in self: ----> if not hasattr(child, 'id'): ----> continue if child.id == elementId: return child

timothycrosley commented 11 years ago

Thanks! Issue has been verified and a fix (likely the one you suggested) will be included in beta 3.