How to use applescript to click a button in a modal window
When I try to close a Safari page, sometimes a popup (a modal window?) shows up asking if I want to "Stay on Page" or "Leave Page". I'm trying to write an applescript to look for such a window and click "Leave Page". I have trouble referencing the popup. Is it treated as a window in Safari? I asked for a count of number of windows and applescript doesn't seem to include this modal window in the count. I tried something like:
tell application "Safari"
set theWindows to every window
repeat with theCurrentWindow in theWindows
if(modal of theCurrentWindow) then
-- appropriate action
end if
end repeat
end tell
end repeat
it looks like "modal of theCurrentWindow" always returns false. So I'm guessing "theWindows" doesn't include the popup. How do I reference the popup so that I can perform some action on it?