This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
40 / 45
Jul 2018

I’m using:
io.appium 6.1.0
selenium-java 3.11.0
guava 24.0-jre.

Try this:
String xmlFormat = driver.getPageSource();
if(xmlFormat.contains(“Your Toast Message Here”)){
System.out.println("Toast message displayed: "+yourToastMessage);
}

  • The first line of instruction will give the xml format of the app page. In this, I got the toast message in one of the tags. It works for me.
    You can put the getPageSource instruction after the desired activity, and since toast messages generally have 2 seconds of timeOut, so the above method will work.

I tried your method but for me is not working.
I don’t think you have a toast message there as far as the getPageSource will find the message you looking for.
Normally if getPageSource is finding the element/text we should be able to identify the element like the rest elements.

Hi @Zuzeac,

We need to check if the xmlFormat string contains the toast message. Whether getPageSource() method is able to capture the exact XML DOM at the time of the toast message getting displayed is dependent on how you tweak wait times to ensure the exact toast message is captured.
You need to give some TimeOut.MILLISECONDS.sleep(200) or 500 before the page source is captured.
Also, the capture has to be done before the toast message vanishes away.
I think the standard of any toast message time out is 2 seconds.

Please let me know after doing it if you are still facing any problems.
More than this, I need to see your code what you are exactly trying to achieve.

Thanks … Cheers :slight_smile:

1 month later

Try this:

long startTime = System.currentTimeMillis(); //fetch starting time
boolean neededStatus;
do{
xmlFormat = driver.getPageSource();
neededStatus = xmlFormat.contains(“Needed”);
}while(!(neededStatus) && (((System.currentTimeMillis()-startTime) <= (5*1000))));

‘5’ is for 5 seconds to wait till the toast message is displayed. Generally standard timeout of a toast message is 2 seconds. You can keep this value around 2 to 5 seconds.

Let me know if this works !

4 months later