From 516099b4c8e58acb2479a1974d701599efa3231a Mon Sep 17 00:00:00 2001 From: Aradhya-Tripathi Date: Thu, 12 Jan 2023 16:13:58 +0530 Subject: [PATCH 1/7] chore: bumped up selenium version --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 8b125f7..a7a4826 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ frappe -selenium==3.141.0 +selenium==4.7.2 pandas==1.5.0 \ No newline at end of file From 1b9bf6315d8a68a108f7304bb622a91b32206aff Mon Sep 17 00:00:00 2001 From: Aradhya-Tripathi Date: Thu, 12 Jan 2023 16:15:45 +0530 Subject: [PATCH 2/7] fix: removed w3c exp option --- bank_integration/bank_integration/api/bank_api.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bank_integration/bank_integration/api/bank_api.py b/bank_integration/bank_integration/api/bank_api.py index 1b1266a..39951fa 100644 --- a/bank_integration/bank_integration/api/bank_api.py +++ b/bank_integration/bank_integration/api/bank_api.py @@ -53,14 +53,13 @@ def logout(self): pass def setup_browser(self): - self.br = webdriver.Chrome(options=self.get_options(), port=12345) + self.br = webdriver.Chrome() def get_options(self): options = Options() options.add_argument("window-size=990,1200") if not frappe.conf.developer_mode: options.add_argument("--headless") - options.add_experimental_option("w3c", False) return options From 29c37fdd698a6d9427fef25c6bf8c53bc4611ef8 Mon Sep 17 00:00:00 2001 From: Aradhya-Tripathi Date: Thu, 12 Jan 2023 16:16:20 +0530 Subject: [PATCH 3/7] fix: password field input --- bank_integration/bank_integration/api/hdfc_bank_api.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bank_integration/bank_integration/api/hdfc_bank_api.py b/bank_integration/bank_integration/api/hdfc_bank_api.py index 2fd43f4..ab7146d 100644 --- a/bank_integration/bank_integration/api/hdfc_bank_api.py +++ b/bank_integration/bank_integration/api/hdfc_bank_api.py @@ -37,8 +37,6 @@ def login(self): cust_id = self.get_element("fldLoginUserId") cust_id.send_keys(self.username, Keys.ENTER) - pass_input = self.get_element("fldPassword") - try: secure_access_cb = self.get_element( "chkrsastu", "id", timeout=2, throw=False @@ -56,7 +54,7 @@ def login(self): "HDFC Netbanking is asking for a CAPTCHA, which we don't currently support. Exiting." ) - pass_input.send_keys(self.password, Keys.ENTER) + self.br.switch_to.active_element.send_keys(self.password, Keys.ENTER) self.wait_until( AnyEC( From 3f5112aad98c09b2ee1999ea600527e8f61d0407 Mon Sep 17 00:00:00 2001 From: Aradhya-Tripathi Date: Thu, 12 Jan 2023 16:18:42 +0530 Subject: [PATCH 4/7] fix: added headless option --- bank_integration/bank_integration/api/bank_api.py | 2 +- bank_integration/bank_integration/api/hdfc_bank_api.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/bank_integration/bank_integration/api/bank_api.py b/bank_integration/bank_integration/api/bank_api.py index 39951fa..0fe5116 100644 --- a/bank_integration/bank_integration/api/bank_api.py +++ b/bank_integration/bank_integration/api/bank_api.py @@ -53,7 +53,7 @@ def logout(self): pass def setup_browser(self): - self.br = webdriver.Chrome() + self.br = webdriver.Chrome(options=self.get_options()) def get_options(self): options = Options() diff --git a/bank_integration/bank_integration/api/hdfc_bank_api.py b/bank_integration/bank_integration/api/hdfc_bank_api.py index ab7146d..442057d 100644 --- a/bank_integration/bank_integration/api/hdfc_bank_api.py +++ b/bank_integration/bank_integration/api/hdfc_bank_api.py @@ -13,7 +13,6 @@ from bank_integration.bank_integration.api.bank_api import BankAPI, AnyEC # Selenium imports -from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.common.exceptions import ( From 9c67815d913dfaa84f67f802b4116e2390baff24 Mon Sep 17 00:00:00 2001 From: Aradhya-Tripathi Date: Thu, 12 Jan 2023 17:09:38 +0530 Subject: [PATCH 5/7] fix: sending password --- bank_integration/bank_integration/api/hdfc_bank_api.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bank_integration/bank_integration/api/hdfc_bank_api.py b/bank_integration/bank_integration/api/hdfc_bank_api.py index 442057d..0d17f2f 100644 --- a/bank_integration/bank_integration/api/hdfc_bank_api.py +++ b/bank_integration/bank_integration/api/hdfc_bank_api.py @@ -53,14 +53,14 @@ def login(self): "HDFC Netbanking is asking for a CAPTCHA, which we don't currently support. Exiting." ) - self.br.switch_to.active_element.send_keys(self.password, Keys.ENTER) + self.get_element("fldPassword").send_keys(self.password, Keys.ENTER) self.wait_until( AnyEC( EC.visibility_of_element_located( ( By.XPATH, - "//td/span[text()[contains(.,'The Customer ID/IPIN (Password) is invalid.')]]", + "//td/span[text()[contains(.,'Your ID and IPIN do not match. Please try again')]]", ) ), EC.visibility_of_element_located((By.NAME, "fldOldPass")), @@ -71,7 +71,8 @@ def login(self): throw="ignore", ) - if not self.br._found_element: + print(self.br._found_element, "herre" * 20) + if self.br._found_element: self.handle_login_error() elif "fldOldPass" == self.br._found_element[-1]: From 69186aad8447f891be48be00e49cd9518824a527 Mon Sep 17 00:00:00 2001 From: Aradhya-Tripathi Date: Thu, 12 Jan 2023 17:11:38 +0530 Subject: [PATCH 6/7] wip: _found_element --- bank_integration/bank_integration/api/hdfc_bank_api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bank_integration/bank_integration/api/hdfc_bank_api.py b/bank_integration/bank_integration/api/hdfc_bank_api.py index 0d17f2f..b6824be 100644 --- a/bank_integration/bank_integration/api/hdfc_bank_api.py +++ b/bank_integration/bank_integration/api/hdfc_bank_api.py @@ -60,6 +60,7 @@ def login(self): EC.visibility_of_element_located( ( By.XPATH, + # Message has changed on incorrect password "//td/span[text()[contains(.,'Your ID and IPIN do not match. Please try again')]]", ) ), @@ -71,8 +72,8 @@ def login(self): throw="ignore", ) - print(self.br._found_element, "herre" * 20) - if self.br._found_element: + # Todo: don't think _found_element as an attribute works anymore in 4+ selenium + if not self.br._found_element: self.handle_login_error() elif "fldOldPass" == self.br._found_element[-1]: From 15ea7e5526a83fef1dd35ed6ea7739ce79660aac Mon Sep 17 00:00:00 2001 From: Aradhya-Tripathi Date: Thu, 12 Jan 2023 17:18:20 +0530 Subject: [PATCH 7/7] chore: cleaning up payment code --- .../bank_integration/api/hdfc_bank_api.py | 5 ++--- .../bank_integration/api/payments.py | 22 +++++++++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/bank_integration/bank_integration/api/hdfc_bank_api.py b/bank_integration/bank_integration/api/hdfc_bank_api.py index b6824be..6043731 100644 --- a/bank_integration/bank_integration/api/hdfc_bank_api.py +++ b/bank_integration/bank_integration/api/hdfc_bank_api.py @@ -93,8 +93,9 @@ def login(self): self.process_otp() elif "fldAnswer" == self.br._found_element[-1]: self.process_security_questions() + else: - self.login_success() + self.logged_in = True def process_otp(self): mobile_no = email_id = None @@ -218,8 +219,6 @@ def handle_login_error(self): self.throw(alert) def login_success(self): - self.logged_in = 1 - if self.doctype == "Bank Integration Settings": self.show_msg("Credentials verified successfully!") self.emit_js("setTimeout(() => {frappe.hide_msgprint()}, 2000);") diff --git a/bank_integration/bank_integration/api/payments.py b/bank_integration/bank_integration/api/payments.py index 3214b0f..0259c83 100644 --- a/bank_integration/bank_integration/api/payments.py +++ b/bank_integration/bank_integration/api/payments.py @@ -8,13 +8,27 @@ import frappe from bank_integration.bank_integration.api import get_bank_api + @frappe.whitelist() def make_payment(docname, uid, data): + doctype = "Payment Entry" data = frappe._dict(json.loads(data)) - bi_name = frappe.db.get_value('Bank Account', {'account': data.from_account}, 'name') - bi = frappe.get_doc('Bank Integration Settings', bi_name) + bi_name = frappe.db.get_value( + "Bank Account", {"account": data.from_account}, "name" + ) + bi = frappe.get_doc("Bank Integration Settings", bi_name) data.from_account = bi.bank_account_no - bank = get_bank_api(bi.bank_name, bi.username, bi.get_password(), doctype="Payment Entry", docname=docname, - uid=uid, data=data) + bank = get_bank_api( + bi.bank_name, + bi.username, + bi.get_password(), + doctype=doctype, + docname=docname, + uid=uid, + data=data, + ) + + if bank.logged_in: + bank.login_success() \ No newline at end of file