如何使用Selenium Web驱动程序自动化OTP? [英] How to automate OTP using selenium web driver?
问题描述
我正在自动进行网站注册,但问题是,一旦我输入手机号,它就会发送OTP.输入otp后,它将要求输入密码,然后我便可以进行注册.
一旦我进入手机号码,是否有任何方法可以获取OTP代码? 或者 我们可以使用Selenium Webdriver自动执行OTP吗?
您可以尝试以下任何一种方法:
解决方案1:
步骤1:通过USB将电话/加密狗连接到COM端口.
第2步:调用用于通过smslib.jar获取短信的代码
获取短信的示例代码:
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);
}
第3步:解析短信以按最新收到的短信从获取的列表中获取 OTP
.
解决方案2:
第1步:连接android手机/iphone.
第2步:如果手机的android系统通过appium(或任何其他自动化应用程序)使SMS应用程序自动化,或者其iPhone使其SMS应用程序功能实现自动化,则在任何一部手机中使SMS应用程序自动化
获取SMS并解析以获取OTP
.
解决方案3:
第1步:注册HTTP SMS网关(其中大多数提供付费的API调用,而很少有免费的API 调用进行测试)
第2步:调用获取短信的方法.
第3步:解析消息(按最新收到的短信排序后)以获取一次性密码
.
这三种获取OTP然后将其发送到Web应用程序的方法.
.
解决方案4:
从DB获取OTP(如果它是内部应用程序还是可以访问的话).
.
'解决方案3和解决方案4 '效率最高,并且对短信接收平台没有任何依赖性.
.
解决方案合并如下:
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 ?
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:
这篇关于如何使用Selenium Web驱动程序自动化OTP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!