How to read OTP from messages using Appium?


I hoped after upgrade to Appium 1.7.0 problem will be solved, but still no success

I tried to find solution in the article you provided, but the problem is that on my real device I can catch everything related to application under test. OTP is not caught since it’s a separate application. Did you mean some particular step?

I install the desctop last version of appium for ios
It is work wonderful and I can get otp code from notification with swipe
there is a problem with search element by xpath, it works very slow


Could you, please, provide your code?
As I described, I see that swipe code works, but cannot catch the OTP text that contains the code
How do you do it?

I can find the msg by XPATH (I have the title of msg)
for example:

Sorry for stupid question: after your swipe do you see code of OTP in inspector?
I don’t :frowning:
Can it depend on application under test permissions?

if you dont see the msg in notification
go to your app setting
and set how you can recieve msg in notification

Asked development engineer of application under test. He said he have no idea about such a setting.
Can you explain, please, what do you mean?

Thanks in advance

Do you see the OTP msg on Notification screen after swipe?

See this video :

As there are two options to read OTP:

  1. Start the activity of the messaging app and then read the otp from there.
  2. Read the OTP from the notification tray.

Below the function to read the OTP in Appium:

public static String readOTP()
    //driver.startActivity("", "");
    String otp = driver.findElementByXPath("//*[contains(@text,'is')]").getText().split("code:" )[0];
    return otp;

Hope this will help !!!