Hi, I’m working on a similar issue at the moment. Something like this might help you (hope so):
tell application "Safari"
set counter to 0
-- the number of links in the front document
set the_link_number to do JavaScript "document.links.length" in document 1
repeat the_link_number times
-- getting the target URL of the first link of the front document
set counter to counter + 1
do JavaScript "document.links[" & counter & "].href" in document 1
end repeat
end tell
tell application "Safari"
set thelink to do JavaScript "document.links[1].href" in document 1
delay 5
set the URL of document 1 to thelink
delay 5
set thelink to do JavaScript "document.links[1].href" in document 1
end tell
My problem is that I need to introduce an if clause so that, if there are any pending orders on our website to be processed (and therefore the number of links on a particular page will be at least 12) the script will proceed to process them, and if there are no orders there, then it will exit.