Commit 7a84806a authored by Vincent Ardisson's avatar Vincent Ardisson Committed by Vincent A

modules: replace cssselect usage with xpath

Almost as simple, one dependency less.
parent 30bf4fee
......@@ -436,7 +436,7 @@ class TransactionsPage(LoggedPage, MyHTMLPage):
if len(tables) == 0:
tables = self.doc.xpath('//table[@id="table-detail"]')
if len(tables) == 0:
tables = self.doc.getroot().cssselect('table.table-detail')
tables = self.doc.xpath('//table[has-class("table-detail")]')
if len(tables) == 0:
assert len(self.doc.xpath('//td[has-class("no-result")]')) > 0
return
......
......@@ -63,7 +63,7 @@ class LoginResultPage(HTMLPage):
else:
self.browser.set_all_readonly(False)
accounts = OrderedDict()
for tr in self.doc.getroot().cssselect('table.compteTable > tbody > tr'):
for tr in self.doc.xpath('//table[has-class("compteTable")]/tbody/tr'):
if len(tr.findall('td')) == 0:
continue
attr = tr.xpath('.//a')[0].attrib.get('onclick', '')
......
......@@ -921,7 +921,7 @@ class IndexPage(LoggedPage, HTMLPage):
continue
# Remove useless details
detail = tr.cssselect('div.detail')
detail = tr.xpath('.//div[has-class("detail")]')
if len(detail) > 0:
detail[0].drop_tree()
......
......@@ -1648,11 +1648,11 @@ class InternalTransferPage(LoggedPage, HTMLPage):
return l[0].iban
def get_account_index(self, direction, account):
for div in self.doc.getroot().cssselect(".dw_dli_contents"):
inp = div.cssselect("input")[0]
for div in self.doc.xpath('//*[has-class("dw_dli_contents")]'):
inp = div.xpath(".//input")[0]
if inp.name != direction:
continue
acct = div.cssselect("span.doux")[0].text.replace(" ", "")
acct = div.xpath('.//span[has-class("doux")]')[0].text.replace(" ", "")
if account.endswith(acct):
return inp.attrib['value']
else:
......
......@@ -250,11 +250,11 @@ class AccountsList(LoggedPage, HTMLPage):
return self.doc.xpath('//input[@id="javax.faces.ViewState"]/@value')[0]
def islast(self):
havemore = self.doc.getroot().cssselect('.show-more-transactions')
havemore = self.doc.xpath('//*[has-class("show-more-transactions")]')
if len(havemore) == 0:
return True
nomore = self.doc.getroot().cssselect('.no-more-transactions')
nomore = self.doc.xpath('//*[has-class("no-more-transactions")]')
return len(nomore) > 0
@property
......
......@@ -50,4 +50,4 @@ class PageUpload(HTMLPage):
class PageFile(HTMLPage):
def has_error(self):
return bool(self.doc.getroot().cssselect('.error'))
return bool(self.doc.xpath('//*[has-class("error")]'))
......@@ -40,20 +40,20 @@ class LoginPage(HTMLPage):
class AccountPage(LoggedPage, HTMLPage):
def get_accounts(self):
for el in self.doc.getroot().cssselect('div#content tr.row'):
for el in self.doc.xpath('//div[@id="content"]//tr[has-class("row")]'):
account = Account()
balance = el.cssselect('td.Balance')[0].text
balance = el.xpath('.//td[has-class("Balance")]')[0].text
account.balance = Decimal(Transaction.clean_amount(balance))
account.id = el.cssselect('span')[0].text.strip()
account.id = el.xpath('.//span')[0].text.strip()
account.currency = u'NZD' # TODO: handle other currencies
account.type = Account.TYPE_CHECKING
if el.cssselect('td.AccountName > a'):
label_el = el.cssselect('td.AccountName > a')[0]
if el.xpath('.//td[has-class("AccountName")]/a'):
label_el = el.xpath('.//td[has-class("AccountName")]/a')[0]
account._link = label_el.get('href')
else:
label_el = el.cssselect('td.AccountName')[0]
label_el = el.xpath('.//td[has-class("AccountName")]')[0]
account._link = None
account.label = unicode(label_el.text.strip())
......@@ -64,10 +64,10 @@ class AccountPage(LoggedPage, HTMLPage):
class HistoryPage(LoggedPage, HTMLPage):
def get_history(self):
# TODO: get more results from "next" page, only 15 transactions per page
for el in self.doc.getroot().cssselect('div#content tr.row'):
for el in self.doc.xpath('//div[@id="content"]//tr[has-class("row")]'):
transaction = Transaction()
label = unicode(el.cssselect('td.tranDesc')[0].text)
label = unicode(el.xpath('.//td[has-class("tranDesc")]')[0].text)
transaction.label = label
for pattern, _type in Transaction.PATTERNS:
......@@ -76,10 +76,10 @@ class HistoryPage(LoggedPage, HTMLPage):
transaction.type = _type
break
date = el.cssselect('td.tranDate')[0].text
date = el.xpath('.//td[has-class("tranDate")]')[0].text
transaction.date = datetime.datetime.strptime(date, '%d %b \'%y')
amount = el.cssselect('td.tranAmnt')[0].text
amount = el.xpath('.//td[has-class("tranAmnt")]')[0].text
transaction.amount = Decimal(Transaction.clean_amount(amount))
yield transaction
......
......@@ -82,8 +82,8 @@ class Transaction(FrenchTransaction):
class SGPEPage(HTMLPage):
def get_error(self):
err = self.doc.getroot().cssselect('div.ngo_mire_reco_message') \
or self.doc.getroot().cssselect('#nge_zone_centre .nge_cadre_message_utilisateur') \
err = self.doc.xpath('//div[has-class("ngo_mire_reco_message")]') \
or self.doc.xpath('//*[@id="#nge_zone_centre"]//*[has-class("nge_cadre_message_utilisateur")]') \
or self.doc.xpath(u'//div[contains(text(), "Echec de connexion à l\'espace Entreprises")]') \
or self.doc.xpath(u'//div[contains(@class, "waitAuthJetonMsg")]')
if err:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment