From 5ae892cbc68b7673777af0314419f0a6ae2ccd9c Mon Sep 17 00:00:00 2001 From: Najam Ul Saqib Date: Thu, 7 Mar 2024 07:50:24 +0500 Subject: [PATCH] add otp selenium script Signed-off-by: Najam Ul Saqib --- selenium/Fill OTP in MFA.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 selenium/Fill OTP in MFA.js diff --git a/selenium/Fill OTP in MFA.js b/selenium/Fill OTP in MFA.js new file mode 100644 index 00000000..c9472173 --- /dev/null +++ b/selenium/Fill OTP in MFA.js @@ -0,0 +1,21 @@ +// This script can be used to fill in the OTP if it appears right after the authentication. +// This can only work for the apps who have fixed OTP in MFA + +function browserLaunched(utils) { + var By = Java.type("org.openqa.selenium.By"); + var Thread = Java.type("java.lang.Thread"); + var url = utils.waitForURL(5000); + var wd = utils.getWebDriver(); + var OTP = "123456"; + + wd.get(url + "#/login"); + Thread.sleep(30000); //Wait for ZAP to handle the auth. + wd.findElement(By.id("one-time-code")).sendKeys(OTP); + wd.executeScript( + "document.querySelector('flt-glass-pane').shadowRoot.querySelector('flt-semantics-placeholder').click({force: true})" + ); //Used with Flutter apps only + Thread.sleep(1000); + wd.executeScript( + "document.querySelector('[aria-label=\"Verify Code\"]').click()" + ); +}