How to automate OTP using selenium web driver?

I am doing automation to register on a website, but the problem is that it sends OTP when I enter my mobile number. after entering otp he will ask for a password, and I can do the registration.

Is there a way to get the OTP code when I find mobile? or Can we automate OTP with selenium webdriver?

+7
source share
4 answers

You can try any of them:

Solution 1:

Step 1: Connect the phone / dongle to the COM port via USB.

Step 2: Call the code to receive SMS via smslib.jar

Sample code for receiving 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: Parsing SMS to receive OTP from the received list by the last received SMS

,

Solution 2:

Step 1: Connect your Android / iPhone phone.

Step 2: Automate the SMS application on any of the phones, if its Android is an SMS application for automation using appium (or any other automation application), or, if its iphone, automate the function of the SMS application,

to receive SMS and parse it to receive OTP

,

Solution 3:

Step 1: Register for the HTTP SMS gateway (most of them provide a paid API call with very few free API calls for testing).

Step 2: calling the method to receive SMS.

Step 3: parse the message (after sorting by the last received SMS) to get OTP

,

In these three ways, you can get OTP and then send it to a web application.

,

Solution 4:

Get OTP from the database if this is your own application or if it can be accessed.

,

β€œ Decision 3 and Decision 4 ” are the most effective and do not depend on SMS receiving platforms.

,

The solutions are consolidated below:

enter image description here

+6
source
 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 works great for automating OTP verification sites. Just create a local Chrome Trust once and call the same browser using the code above for testing. This is pretty cool :)

0
source

Someone please help me, I am trying to send an online form that sends OTP to email. I want to automate this OTP in a browser / online form. Please suggest.

0
source

If the OTP code is stored in db, it is easy to automate. you can use sql connection and get otp code.

-2
source

Source: https://habr.com/ru/post/1245127/


All Articles