Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

aapl-danial

macrumors newbie
Original poster
Feb 8, 2013
19
0
I'm messing with a script to select a form based off a "select" button, except the webpage could have several identical "select" buttons, and I need to always choose the last one. Here is the page source data for a webpage with 4 submit buttons, all named the same:

And here is my javascript written in AS to try and get it.


Code:
	tell application "Safari"
				do JavaScript "document.forms[contactform].submit();" in document 1
			end tell

I'm wondering if there is a way to title each submit button 0,1,2... then another command to select the last one? I'm a bit stuck on this one. Thanks!
 

Attachments

  • Screen Shot 2014-07-26 at 11.00.33 AM.png
    Screen Shot 2014-07-26 at 11.00.33 AM.png
    54 KB · Views: 153
  • Screen Shot 2014-07-26 at 11.00.55 AM.png
    Screen Shot 2014-07-26 at 11.00.55 AM.png
    49.3 KB · Views: 127
It's gotta be something with lastChild correct? I'm super stuck on this one. Someone must know
 
Try this:
Code:
tell application "Safari"
	do JavaScript "document.contact.recipient.value = \"delqcoll@dekalbcountyga.gov\";" in document 1
end tell

This will give you come background on the technique.
http://www.javascriptkit.com/javatutors/combos1.shtml

In this case we don't have a simple 1, 2, 3 . . . values like the above link will show.

Code:
<select name="recipient" onchange="checkForm(this.form)" style="background-color:#D9E8FF">
  <option value="">Please select from the following...</option>
  <option value="motorveh@dekalbcountyga.gov">DeKalb County Vehicle Registration</option>
  <option value="proptax@dekalbcountyga.gov">DeKalb County Property Tax</option>
  <option value="delqcoll@dekalbcountyga.gov">DeKalb County Delinquent Property Tax</option>
</select>

Substitute whatever the VALUE is for the item you want in the AppleScript/Javascript you execute.

I'm assuming you are working with a page something like:
http://web.co.dekalb.ga.us/TaxCommissioner/Contact.asp
If what you have is different then post the URL and I'll take a look.

-numero
 
Does the form submit button have an ID? If yes, it's an easy solution to use applescript to click the button with that ID.
 
Try this:
Code:
tell application "Safari"
	do JavaScript "document.contact.recipient.value = \"delqcoll@dekalbcountyga.gov\";" in document 1
end tell

This will give you come background on the technique.
http://www.javascriptkit.com/javatutors/combos1.shtml

In this case we don't have a simple 1, 2, 3 . . . values like the above link will show.

Code:
<select name="recipient" onchange="checkForm(this.form)" style="background-color:#D9E8FF">
  <option value="">Please select from the following...</option>
  <option value="motorveh@dekalbcountyga.gov">DeKalb County Vehicle Registration</option>
  <option value="proptax@dekalbcountyga.gov">DeKalb County Property Tax</option>
  <option value="delqcoll@dekalbcountyga.gov">DeKalb County Delinquent Property Tax</option>
</select>

Substitute whatever the VALUE is for the item you want in the AppleScript/Javascript you execute.

I'm assuming you are working with a page something like:
http://web.co.dekalb.ga.us/TaxCommissioner/Contact.asp
If what you have is different then post the URL and I'll take a look.

-numero

Thanks, I'm messing around with this one: https://paulding.paytaxes.net/customer/enhanced_property_tax_search.php

Perform the search for say R053188 under PPIN, and the results below list several years. I always need to Select the final entry, or most recent year, 2013. Trouble is under source they're all the same name, form name and Select value. No ID.

Then there's one like this: with only one entry. Hmm. Thanks!
R032686
 
Code:
tell application "Safari"
	do JavaScript "var len = document.contactform.length;document.contactform[len-1].submit();" in document 1
end tell

You ask the contactform array how many items it has. Then you perform the submit() function on the last one. The array starts at zero so the last form is the length minus 1.

-numero
 
Thanks! I'm still getting a "missing value" error in the replies as it skims over onto the next.

here is my code:

Code:
set this_file to (((path to desktop folder) as string) & "TaxFile_Paulding.txt")

set tabChar to tab

set numbersFile to paragraphs of (read POSIX file "/Users/rickystrom/Desktop/propNumbers_Paulding.txt")

tell application "Safari"
	activate
	make new document
	set safariWindow to front window
	
	repeat with nextLine in numbersFile
		if length of nextLine is greater than 0 then
			
			set the clipboard to nextLine
			
			set URL of tab 1 of safariWindow to "https://paulding.paytaxes.net/customer/enhanced_property_tax_search.php"
			delay 2
			tell application "System Events"
				repeat 5 times
					keystroke tab using option down
				end repeat
				delay 1
				keystroke "v" using command down
				delay 1
				keystroke tab
				key code 36
				delay 8
			end tell
			
			tell application "Safari"
				do JavaScript "var len = document.contactform.length;document.contactform[len-1].submit();" in document 1
			end tell
			
			
			set pageText to text of current tab of safariWindow
			
			
			
		end if
	end repeat
end tell

Again thanks for getting me this far! I didn't know two calls could be inside the JS

EDIT: Geez added a small delay after the do javascript and it's working. weird.
 
Last edited:
I think you may find that for properties with a single owner (a single contactform form) you will get an error with the javascript. When there isn't an array of contactforms I was getting 10 returned as the length. I don't understand why. I also noticed when there were multiple owners it doesn't matter which one is submitted. You always get the payment records for all owners. So my solution was to try to click on the first contactform (contact form[0]). That will work if there is more than one owner listed. If that errors out then there must just be one button so call it without the index value.

If you have it running on your system then let it ride. If you end up having the same issue that I did then here is your fallback code.

Code:
set this_file to (((path to desktop folder) as string) & "TaxFile_Paulding.txt")

set tabChar to tab

set numbersFile to paragraphs of (read POSIX file "/Users/numero/Desktop/propNumbers_Paulding.txt")

tell application "Safari"
	activate
	make new document
	set safariWindow to front window
	
	repeat with nextLine in numbersFile
		if length of nextLine is greater than 0 then
			
			set the clipboard to nextLine
			
			set URL of tab 1 of safariWindow to "https://paulding.paytaxes.net/customer/enhanced_property_tax_search.php"
			delay 2
			tell application "System Events"
				repeat 5 times
					keystroke tab -- using option down
				end repeat
				--delay 1
				keystroke "v" using command down
				--keystroke tab
				key code 36
				delay 8
			end tell
			
			tell application "Safari"
				do JavaScript "
				try {
					document.contactform[0].submit();
					/*alert (\"Multiple Forms\")*/
				}
				catch(err)
				{
		    			document.contactform.submit();
					/*alert (\"Single Form\")*/
				};
				" in document 1
				
			end tell
			
			delay 8
			
			set pageText to text of current tab of safariWindow
			
		end if
	end repeat
end tell

I removed the tab after the Command-V. It is not needed. I also removed the delay between the tabs and the paste. That shouldn't be needed as well.

I took out the "using option down" on the tabbing. Must be a setting in your browser for tabbing from field to field. Set as needed for you.

The alerts() are commented out in the javascript. You can put them back in if you want to do a short run of tests to see how it is working. Just take them back out before you go into production since someone will have to be there to dismiss the dialogs or your processing will get messed up. Applescript won't know that the browser is waiting for a message to be dismissed.
 
But I can brick it if an entry only has one form. Why would that be? For example: R000196

That has one form, and the script says len-1, which is 1-1=0, should be right as any other.
 
Mine is returning 10 on that page for some reason. That is why I did the work-around.
 

Attachments

  • Screen Shot 2014-07-27 at 8.13.09 PM.png
    Screen Shot 2014-07-27 at 8.13.09 PM.png
    94 KB · Views: 124
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.