Toast messages handling using robot framework

Hi,
How to automate toast messages using robot framework?
In my web application under test there are different toast messages on different location.
These messages display for 3 seconds and then gets fade away.
Unable to get the locator for it.
I am using robot framework in eclipse red editor, python, selenium.
Thanks !

You might need to pause the browser while the toast message is being shown to then be able to figure out it’s CSS/Xpath locator. It can be a bit tricky and I think it is a little different’ between using Chrome or Firefox. I think for Chrome you have to hit F8 while DevTools is open and you have activated the Sources tab. It takes a bit of trial and error to time it just right so don’t despair if you struggle.

1 Like

Use FLAUI Inspect to get the xpath of the Toast Notification and try clicking it via FLAUI Library. sometimes this works. It takes a bit of trial and error.

I usually inspect the button that triggers the toast message to find the function it calls (on-click) and put, then using dev tools put a break point in the function and then click it, if you get it right the break point stops the toast message from disappearing and you can figure out the selector.

1 Like

I was able to detect Toast messages using

  • Wait Until Page Contains Element or
  • Wait Until Page Contains keywords

Code Snippet

# login_page.robot
...

*** Variables ***
...
${TOAST_MESSAGE}    xpath=//android.widget.Toast[@text="Toast message."]

...
*** Keywords ***
...
Detect Toast Message After Login
...
    Wait Until Page Contains Element    ${TOAST_MESSAGE}
    Wait Until Page Contains    Toast message.    # Alternative

Prerequisites:

  1. UiAutomator2 version 6.7.8
  2. Appium version 3.1.2
  3. Robot Framework version 7.4.1
  4. Python version 3.12.6
1 Like