How to read toast message in android

Hi all,
How to read toast message in android version 7.

1 Like

I am also facing the same issue. Any Solution?

Solution found.

Use mobile screen(s) captured, then using the approach here to automate:

Do you have any sample scripts here?

@Chew Mong Leng do you have any samples?

Hi U.G.,

You can try this for Android toasts:

import io.appium.java_client.AppiumDriver

AppiumDriver<?> driver = MobileDriverFactory.getDriver()
def toast = driver.findElementByXPath("//android.widget.Toast[@text='Added to cart']")

Hope this helps,



@Chris_Trevarthen This code didn’t work.

Can not capturer Toast message on Android. were you able to capture Toast message?

Hi @GeneralChingChicken,

I’m able to capture the toast message on an Android emulator using API v27. Note that my tests are using “uiautomator2”, which I think is what’s required for capturing the toasts. I didn’t have to do anything special to set that up, though, it seemed to be the default. You should be able to see in your logs the automationName property of Desired Capabilities whether uiautomator 2 is being used.

I wonder if you could log out what Appium thinks is on the screen at the time when the toast appears. If you want to see some more detail about exactly what Appium/Katalon detects on the screen you can log out the XML contents of the screen. You should be able to do that by putting the following import statements at the top of your test case:

import com.kms.katalon.core.logging.KeywordLogger
import io.appium.java_client.AppiumDriver

Then in the code for your test, add the following right after the toast is expected to appear:

AppiumDriver<?> driver = MobileDriverFactory.getDriver()
KeywordLogger log = new KeywordLogger()

When the test runs, you should see an entry in the Log Viewer for “Statement - log.logInfo(driver.getPageSource())” that shows the start of the XML for the screen. If you tap on it, you’ll see all of the XML for the screen on the right-hand pane.

I would check that XML to see if the toast shows up there. If not, then you might consider adding a MobileBuiltInKeywords.delay() of a second and try printing the screen again to see if the test check is firing before the toast appears.

Hope this helps,




My XML isn’t picking up the toast message. I try adding the delay but nothing is showing up.
is your value for automationName - “uiautomator 2” with a space or “UiAutomator2”?

AppiumDriver<?> what goes inside the "<?>"
–What version of Appium do you have?

Hi @GeneralChingChicken,

When logging my Desired Capabilities, the automationName shows as uiautomator2 (all one word, all lower case). Here’s what my full Desired Capabilities output looks like:

  "deviceName":"emulator-5554 (Android SDK built for x86 - Android 8.1.0)",

If you walk through your app with the Katalon Mobile Spy, are you able to see the toast, especially are you able to capture it as a Test Object when it shows on your screen? If not, that might be a sign of some other incompatibility with an Android SDK version.

– Chris



Object Spy Isn’t seeing Toast message object. – I will continue my investigation and see what I can find and up this this forum

Hi @GeneralChingChicken,

I’ve been reading some Appium github posts from people who were unable to view toast messages, and it seems to point to having older versions of Android SDK. I wonder if you’re able to update your version of Android Studio to the latest, could you see the toast messages in the Spy Mobile then?

– Chris

Did that yesterday but I think I uninstall my VDs and reinstall them and try again.

1 Like

I updated/reinstalled Android SDK and all my VD.
I am running 5.10 katalon studio
I am running 1.10 Appium - uiautomator2 driver

Still not seeing - toast message

Hi @GeneralChingChicken,

That’s interesting - I would not have expected Appium 1.10 to work at all (it’s been my experience that Katalon didn’t work with anything higher than Appium 1.8.1). I’m using Appium 1.8.1 and Katalon Studio 5.10.1. Any chance you could try with Appium 1.8.1?

NOTE: Appium 1.8.1 isn’t the same as Appium Desktop 1.8.1 - it’s a bit confusing with the version numbers. If you’re using Appium Desktop, you’ll need Appium Desktop 1.6.3.

– Chris

1 Like

Sorry guys was not on this forum actively.

@Zarashima, @U.G.Chinthaka_Devind, here the sample code that works on basic OCR:

  1. First you make use Katalon API to capture some pictures/snapshots:
    SnapTotal = total snapshots
    ScrSnapDir = path to store snapshots as you would need to clear this prior snapshot, sorta like working directory for OCR.
    for (def index : (0…SnapTotal)) {
    String filename = Mobile.concatenate([
    ‘.png’] as String[], FailureHandling.STOP_ON_FAILURE)
    Mobile.takeScreenshot(filename, FailureHandling.STOP_ON_FAILURE)

  2. You need Tess4j (tess4j-4.0.1.jar, in my case) for the basic OCR as here I not involving yet OpenCV (see another topic created today). Here the basic codes:
    Tesseract instance = new Tesseract();

    Since Tess4j v4alpha, the whitelist seems broken; thus, left out from here.
    Basically variables, you can assign via Katalon Profiles:
    TessDataLang = ‘eng’
    TessDataDir = ‘D:\Dev\tools\tessdata.ocr’ <- this host the Eng data dictionary (eng.traineddata)
    Get files from:

  3. Code to perform simple OCR, where imageFile is individual full-path-filename that you snapped earlier that you can perform a loop scan to stop when the TEXT you looking for found.
    try {
    String result = instance.doOCR(imageFile);
    catch (TesseractException e) {
    return ‘Error while reading image’


    1. result basically containing TEXT that from OCR.
    2. If no matched TEXT found after all snapped files processed and you sure one of the image is containing the TEXT that needs recognized; this you would need OpenCV to further enhanced the image for more ‘finer’ before passing to doOCR().
  4. Here the list of Java imports used and you need to place all the depending JAR files imported to Katalon Project or manual copy to Drivers folder (restart Katalon) you are sorted.
    import net.sourceforge.tess4j.Tesseract as Tesseract;
    import net.sourceforge.tess4j.TesseractException as TesseractException;

Let me know any further help needed.



At least once, you would need the Mobile simulator for generating the snaps.

For the above simple OCR, you don’t need Appium or any Device-simulator to up, you can even create a simple UT just for OCR testing to one or some picture files.

You can make use, e.g., Chrome Headless for the UT.

@GeneralChingChicken, there are a few ways you can take photo of the toast message:

  1. Manually and the toast message stay ‘long’ enough for the snap, e.g., Spy Mobile.

  2. Automatically using loop, see my sample code step-1 (above).
    That to perform right after some ‘simulation’ steps of which surely will trigger the toast message to appear, you just snap for some pictures immediately after your/the submission.

Before you get to either option 1 or 2, ensure you can manually simulate the toast-message successfully for starter.


1 Like


Still no luck,

I did what you mention, and ran object spy but still no luck. No clue whats going on.

@GeneralChingChicken, you cannot use latest Appium version, but to downgrade it.
Try this command for specific version:
npm install -g appium@1.8.1

Check Katalon supported versions here.

Also, read here further details in relating to above npm command.

After npm install appium, you can then installing appium-doctor as I find this useful to help you resolved any other dependent issues or installer.


Hi @GeneralChingChicken,

To help diagnose further, could you share the console log when you run your test? I’m especially interested in what Appium thinks is on the screen at the time the toast shows up (that’s the output from the driver.getPageSource() command I mentioned above. However, having the full console log would be helpful.

Also, I realized that I didn’t answer your question from above about what what version of Appium or what goes in the “?” for AppiumDriver<?>.

I’m using Appium Server 1.8.2-beta (although 1.8.1 should be fine for Android).

As for the “?”, you just leave it as-is - it’s sort of a wildcard when accessing some types of classes.