diff --git a/modules/sogecartenet/browser.py b/modules/sogecartenet/browser.py index 5878b0b7b4645ddf26c101c414780a4f50dda2fb..c3934ee1303e20fabd783fdd36485bd52d7d8ec7 100644 --- a/modules/sogecartenet/browser.py +++ b/modules/sogecartenet/browser.py @@ -17,10 +17,12 @@ # You should have received a copy of the GNU Lesser General Public License # along with this weboob module. If not, see . +from __future__ import unicode_literals + from datetime import date from weboob.browser import URL, need_login -from weboob.exceptions import BrowserIncorrectPassword +from weboob.exceptions import BrowserIncorrectPassword, ActionNeeded from weboob.browser.selenium import ( SeleniumBrowser, webdriver, AnyCondition, IsHereCondition, VisibleXPath, @@ -61,10 +63,18 @@ def do_login(self): self.wait_until(AnyCondition( IsHereCondition(self.accueil), VisibleXPath('//div[@id="labelQuestion"]'), + VisibleXPath('//div[contains(@class, "Notification-error-message")]'), )) if not self.accueil.is_here(): - raise BrowserIncorrectPassword(self.page.get_error()) + assert self.login.is_here(), 'We landed on an unknown page' + error = self.page.get_error() + if any(( + 'Votre compte a été désactivé' in error, + 'Votre compte est bloqué' in error, + )): + raise ActionNeeded(error) + raise BrowserIncorrectPassword(error) @need_login def iter_accounts(self): diff --git a/modules/sogecartenet/ent_browser.py b/modules/sogecartenet/ent_browser.py index b90c92b90e27037549f05124791374992971c070..77cb555a5e3d633682dd341b6d042407dfb29abe 100644 --- a/modules/sogecartenet/ent_browser.py +++ b/modules/sogecartenet/ent_browser.py @@ -17,10 +17,12 @@ # You should have received a copy of the GNU Lesser General Public License # along with this weboob module. If not, see . +from __future__ import unicode_literals + from datetime import date from weboob.browser import URL, need_login -from weboob.exceptions import BrowserIncorrectPassword +from weboob.exceptions import BrowserIncorrectPassword, ActionNeeded from weboob.tools.capabilities.bank.transactions import sorted_transactions from weboob.browser.selenium import ( SeleniumBrowser, webdriver, AnyCondition, VisibleXPath, IsHereCondition, @@ -65,19 +67,20 @@ def do_login(self): self.page.login(self.username, self.password) - # Error message are displayed with javascript and automatically - # disappear after a few seconds, so it is hard to catch them at - # the right time. self.wait_until(AnyCondition( IsHereCondition(self.accueil), VisibleXPath('//div[contains(@class, "Notification-error-message")]'), )) if not self.accueil.is_here(): - # Message are displayed with javascript and disappear after - # a few seconds, so we might get errors trying to retrieve - # the error message. - raise BrowserIncorrectPassword() + assert self.login.is_here(), 'We landed on an unknown page' + error = self.page.get_error() + if any(( + 'Votre compte a été désactivé' in error, + 'Votre compte est bloqué' in error, + )): + raise ActionNeeded(error) + raise BrowserIncorrectPassword(error) @need_login def iter_accounts(self): diff --git a/modules/sogecartenet/ent_pages.py b/modules/sogecartenet/ent_pages.py index d03d7a18dd63527beec6dbf0cec61e0023870caa..d36afb7b6276589dec1fd0785273fd729c255968 100644 --- a/modules/sogecartenet/ent_pages.py +++ b/modules/sogecartenet/ent_pages.py @@ -53,6 +53,9 @@ def login(self, username, password): el.send_keys(Keys.RETURN) + def get_error(self): + return CleanText('//h1[contains(@class, "Notification-caption")]')(self.doc) + class AccueilPage(LoggedPage, SeleniumPage): is_here = VisibleXPath('//div[@id="Menu-responsive"]') diff --git a/modules/sogecartenet/pages.py b/modules/sogecartenet/pages.py index 4b52a1056fe5c61070b40cfbb60f618fc09b537e..d91b5700d00462f54bd2fe0587792031090b1f38 100644 --- a/modules/sogecartenet/pages.py +++ b/modules/sogecartenet/pages.py @@ -33,7 +33,10 @@ class LoginPage(_LoginPage): def get_error(self): - return CleanText('//div[@id="labelQuestion"]')(self.doc) + return ( + CleanText('//div[@id="labelQuestion"]')(self.doc) + or CleanText('//h1[contains(@class, "Notification-caption")]')(self.doc) + ) class PreLoginPage(SeleniumPage):