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