do Javascript targeting links

Hello:

Brand new to the forum, but I’m glad I’ve found it.

I’ve been able to automate a script for logging into a web site, and then hitting submit using the ‘do javascript’ command.

My question is on the next page, I want to be able to click on a text link…I can target the using this:

do JavaScript "document.links[0].href" in document 1

Is there a command to click on the link?

Thank you.

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.

Any ideas?

Cheers,

kev