Hi everyone,
Please help me in copying OTP from message my requirement is as follows
App sends an OTP.
Go to Notifications and drag the bar…
Click on the sender’s name and open the message.
Read OTP from the message and sent it back to the app.
Would be great help i am searching for many days for this but no help
Hi Sachin,
use the switching concept …you can handle the OTP.!!!
1.Before switching to another application i.e(message) you should know the Activity and package name of it.
2.Read the OTP message and store/write the OTP in Excel sheet.
3.Switch to main application with it Activity and package name.
4.Read the the OTP from excel sheet and write into application.
Thanks,
Amit
@Sachin_Savanur
Try this
As there are two options to read OTP:
Start the activity of the messaging app and then read the otp from there.
Read the OTP from the notification tray.
Below the function to read the OTP in Appium:
public static String readOTP()
{
//driver.startActivity (“com.android.mms”, “com.android.mms.ui.ConversationList”);
driver.openNotifications();
String otp = driver.findElementByXPath("//*[contains(@text ,‘is’)]").getText().split(“code:” )[0];
return otp;
}
anurut
July 4, 2019, 10:19am
5
I have done it the way it is asked i.e. using Notification panel to read OTP.
No need to remember the current running activity, no switching
Steps
Open the notification panel by using
driver.openNotifications();
Now loop through the textView class looking for text containing “OTP”
extract the OTP from the text using string manipulation
close the notification screen using
driver.pressKey(new KeyEvent(AndroidKey.BACK));
Enter the extracted OTP
To know more in detail you can go to my GitHub project here