An Apple Script to fetch the

In order to fetch the unexpected pop-up dialog window when executing e2e tests. For example:

I write a simple Apple script get_popup_windows.scpt as follows:

tell application "System Events"
tell process "SystemUIServer"
        set securityAlertWindows to (every window whose subrole is "AXDialog")
        set securityAlertTitles to {}

        repeat with securityAlertWindow in securityAlertWindows
            set securityAlertTitle to (securityAlertWindow's title as text)
            set end of securityAlertTitles to securityAlertTitle
        end repeat
    end tell
end tell

return securityAlertTitles

However, when I execute osascript get_popup_windows.scpt It returns empty even when there is a popup window in my mac. Does anyone know the reason? Thanks for help.

Will