Applescript check if clicking on a button form a different page is loaded

I have a script to repeat 10 times clicking on a form button.


set url1 to "https://site.tdl/page1.html" 
set url2 to "https://site.tdl/page2.html"
tell application "Safari"
tell window 1
set current tab to (make new tab with properties {URL:url1})
repeat 10 times
delay 5
tell application "Safari" to do JavaScript "document.getElementById('SelectedButton').click();" in document 1
end repeat
end tell
end tell


Regularly the form action loads the same page.

In repeat section I want to check if the url has changed.

Something like

if URL has change (or current URL=url2)
my sendMail()
exit repeat
end if


Thanks for any help. I was looking for similar question but couldn't adapt answers to my needs.




iMac 27″, macOS 12.7

Posted on Apr 8, 2025 4:51 PM

Reply

There are no replies.

Applescript check if clicking on a button form a different page is loaded

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.