17

I am doing automation for registration in a website but the problem is that it sends an OTP once i enter mobile no. after enter otp it will ask for password and than i am able to do registration.

Is there any way to get the OTP code once i enter mobile no ? or Can we automate OTP using selenium webdriver ?

3
  • 2
    maybe you can try this, smsenabler.com Commented Mar 16, 2016 at 4:56
  • after you enter the phone no, wait until it forward the sms message to your computer. Then use the message to do next step. But it may be annoying to setup all the stuff. Commented Mar 16, 2016 at 4:57
  • Not specific to selenium but you can set development and production project environments and can skip all otp verifications if the set environment is development. Commented Apr 3, 2017 at 13:53

2 Answers 2

16

You may try any one of them:

Solution 1:

Step 1: Connect the Phone/Dongle to the COM Port via USB.

Step 2: Call the code for fetching sms via smslib.jar

Sample Code to fetch sms:

public void sendSMS() throws Exception{
    OutboundNotification outboundNotification = new OutboundNotification();
    SerialModemGateway gateway = new SerialModemGateway("modem.com5", "COM5", 9600, "ZTE", "COM5");
    gateway.setInbound(true);
    gateway.setOutbound(true);
    gateway.setSmscNumber("+91XXXXXXXXXX"); // 10-digit Mobile Number
    Service.getInstance().setOutboundMessageNotification(outboundNotification);
    Service.getInstance().addGateway(gateway);
    Service.getInstance().startService();
    OutboundMessage msg = new OutboundMessage(ExcelConnect.strSMSTo, ExcelConnect.strSMSText);
    Service.getInstance().sendMessage(msg);
    System.out.println(msg);
    System.out.println(ExcelConnect.strSMSTo + "-" + ExcelConnect.strSMSText);
    Service.getInstance().stopService();
    Service.getInstance().removeGateway(gateway);
}

Step 3: Parse sms to get the OTP from the fetched list by latest received sms

.

Solution 2:

Step 1: Connect the android phone / iphone.

Step 2: Automate the SMS App in either of the phone, if its android - automate SMS app via appium(or any other automating app) or if its iphone - automate its SMS app feature,

to get the SMS and parse it to get the OTP

.

Solution 3:

Step 1: Register for the HTTP SMS Gateway(Most of them provide paid API Call with very few free API Calls for testing).

Step 2: Call the method to fetch SMS.

Step 3: Parse the message(after sorting it by latest received sms) to get the OTP

.

These three ways you can get the OTP and then you can send it to you Web Application.

.

Solution 4:

Get the OTP from DB, if its in-house application or if it can be accessed.

.

'Solution 3 and Solution 4' being most efficient and it doesn't have any dependency on sms receiving platforms.

.

Solutions consolidated below:

enter image description here

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

2 Comments

Can you specify the correct dependency of the smslib.jar in Maven repository?
-1
String userProfile= "C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\User Data\\";
        System.setProperty("webdriver.chrome.driver","C:\\Users\\user\\Desktop\\chromedriver.exe");
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--user-data-dir="+userProfile);
        options.addArguments("--profile-directory=Default");
        options.addArguments("--start-maximized");
        WebDriver driver = new ChromeDriver(options);
        driver.get("https://mail.google.com/mail/u/0/#inbox");

The above code working fine for Automate the OTP verification sites..just create your local chrome trusted one time and call same browser using above code for testing..its quite cool :)

2 Comments

Hey @Samina sheikh, can you explain a bit more in details?
yeah sure! first open your chrome browser of your system where you want to do automation(eg. even on server)..than login the website manually and request for OPT code and enter OTP code. now your browser is trusted browser..and at last run the above code which is in java(working in c# too) and see the magic:)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.