web order script

I’d like to write a script to automate the purchase of my bus tickets.

I found this thread http://macscripter.net/viewtopic.php?id=15651 but I’m having trouble wrapping my head around it, even though it seems to lay it out quite simply.

Ultimately, from this page https://mta.maryland.gov/pass-store/commuter-bus-ten-trip-ticket-zone-3 I’d like to automate opening the URL (easy), clicking the Add to Cart button, changing the quantity from 1 to 3, clicking the Checkout button, filling out the fields /dropdowns, and finally clicking the Review Order button.

Any help would be greatly appreciated.

Mike

Model: Mac Pro
AppleScript: 2.1.2
Browser: Safari 534.55.3
Operating System: Mac OS X (10.6)

If you log in to your account first you won’t have to fill out the fields each time.


tell application "Safari"
	activate
	set URL of document 1 to "https://mta.maryland.gov/pass-store/commuter-bus-ten-trip-ticket-zone-3"
	delay 3
	do JavaScript "document.getElementsByClassName('form-submit node-add-to-cart')[0].click()" in document 1
	delay 3
	do JavaScript "document.getElementById('edit-items-0-qty-wrapper').childNodes[1].value=1 ; document.getElementById('edit-checkout').click()" in document 1
end tell

First off, thanks for the response. When I try your code it opens the URL, but it is not “clicking” the button. I’m getting a “missing value” on the second do JavaScript.

As for logging in, we are not allowed to log in. Don’t ask me why; the only answer I could give is bureaucracy.