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?

3 Answers 3

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:

Sign up to request clarification or add additional context in comments.

Comments

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();

2 Comments

What OP wants is to solve the OTP, and what you suggested there is a library for OTP system.
To solve the OTP it is not as simple as looking for the OTP and it is ready, you must select the iframe before.
-1
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

1 Comment

Seems copied from another answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.