Fix crash when no data available

This commit is contained in:
Florent 2013-02-01 10:40:08 +01:00
commit 87f8b74ab1

View file

@ -32,21 +32,22 @@ class DetailsPage(BasePage):
def on_loaded(self): def on_loaded(self):
self.details = [] self.details = []
table = self.document.xpath('//table[@id="reportTable"]')[0] table = self.document.xpath('//table[@id="reportTable"]')
for tr in table.xpath('tbody/tr'): if len(table) > 0:
detail = Detail() for tr in table[0].xpath('tbody/tr'):
# Skip global category detail = Detail()
if tr.find('td/a') is not None: # Skip global category
continue if tr.find('td/a') is not None:
if tr.attrib["class"] == "totalAmount": continue
continue if tr.attrib["class"] == "totalAmount":
tds = tr.xpath('td') continue
detail.label = unicode(tds[0].text.strip()) tds = tr.xpath('td')
detail.infos = unicode(tds[1].text.strip()) detail.label = unicode(tds[0].text.strip())
detail.price = Decimal(tds[2].text.split(' ')[0].replace(',', '.')) detail.infos = unicode(tds[1].text.strip())
detail.price = Decimal(tds[2].text.split(' ')[0].replace(',', '.'))
self.details.append(detail) self.details.append(detail)
def get_details(self): def get_details(self):
return self.details return self.details