How do I select a anchor tag in JavaScript from AppleScript

I volunteer with a non-profit that maintains a database of all of its classes,
workshops, etc. I have written a number of AppleScripts that take advantage of the
“do JavaScript” function in Safari to post data about the events to sites that
advertise events. The purpose of this is to avoid rekeying the data in the database.
I review all posts before they are submitted and I do all of the Captchas manually.

I am now working on a web page with the following html.

Select your Event date

Clicking on either link causes a different

to be displayed. I can
get to the right link using the following:


tell application "Safari"
	do JavaScript "

	var jLinks = document.getElementsByTagName('a');

	for (var i = 0; i < jLinks.length; i++) {
	
	    if (jLinks[i].innerHTML == 'Calendar View') {
	        alert(jLinks[i].innerHTML);
	        // How do I select jLinks[i]?
	    }
	    if (jLinks[i].innerHTML == 'Advanced View') {
	        alert(jLinks[i].innerHTML);
	        // How do I select jLinks[i]?
	     }
	}
" in document 1
end tell

What I can’t figure out how to do is to select the link in JavaScript.

When it is a link that points to a page, I just grab the URL and load the page,
but here I want the “side effects” of the link which were presumably set by
some other JavaScript.

Suggestions?

Thanks,

Jerry

Model: iMac
AppleScript: How do I find this?
Browser: Safari 531.21.10
Operating System: Mac OS X (10.5)

I am not a serious JavaScript programmer, but for non-button elements, you have to simulate the mouse click. You try might defining and using this function to simulate a mouse click and fire the associated JavaScript event handlers.

Chris,

Thanks for the response. The function looks promising and I’ll certainly give it a try.

Jerry