2

Using selenium webdriver I am testing login page and some more tabs using eclipse, maven, testng, but in Login page there is OTP verification. So I put OTP manually so. How to continue next proces as a automation?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
upen kale
  • 21
  • 2

2 Answers2

3

To continue automation after entering OTP manually using Selenium would be to use the Scanner class as follows:

driver.findElement(By.xpath("xpath_mobile_field")).sendKeys("9818414799");
scanner_user = new Scanner(System.in);
System.out.println("Enter the OTP: ");
String user = scanner_user.nextLine();
driver.findElement(By.xpath("xpath_otp_field")).sendKeys(user);

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

You don't need to enter that manually, you can use someone's otp generator library, like pyotp in python.

import pyotp
totp = pyotp.TOTP('HASHXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
ida2f = totp.now()

for java do you have https://github.com/BastiaanJansen/otp-java

To resolve the OTP, you generally need to select the "iframe" first, for example in python.

                            try:
                                iframe = driver.find_element(By.XPATH, '//*[@id="xxxxxOTP"]')
                                driver.switch_to.frame(iframe)

                                iKeys = 0
                                for strs in ida2f:
                                    iKeys = iKeys + 1
                                    driver.find_element(By.XPATH, f'//*[@id="xxxx-html"]/body/div[2]/div[1]/div/div/div/fieldset/div/input[{iKeys}]').click()
                                    time.sleep(0.1)
                                    driver.find_element(By.XPATH, f'//*[@id="xxxx-html"]/body/div[2]/div[1]/div/div/div/fieldset/div/input[{iKeys}]').send_keys(strs)
                                    time.sleep(0.1)

                                driver.switch_to.default_content()
                                time.sleep(3)
                            except:
                                continue

To be reliable, I like to send key by key, and remember about the iframe, it is very important.

For example (java):

driver.switchTo().frame("xxxxxxx");

And remember go to default frame after:

switchTo().defaultContent();
boludoz
  • 36
  • 4
  • What OP wants is to solve the OTP, and what you suggested there is a library for OTP system. – KunLun Aug 20 '22 at 09:35
  • To solve the OTP it is not as simple as looking for the OTP and it is ready, you must select the iframe before. – boludoz Aug 20 '22 at 14:21