setting a variable to text in a web form

so, i have learned how to FILL web forms with javascript using applescript, but now i need to know if i can have applescript PULL the data that is currently in a cell on a form? i’m using chrome to pull open a page, select an option from a drop down menu, and when the option is selected, one of the fields on the page is automatically filled in with information. i need my applescript to check the value of that field to see if it matches with another variable. any idea on how to get that data? i know i can input the data by using:


		execute javascript "document.forms['FormName']['FieldName'].value = 'data'"

…but how to i GET the data from a field and set a variable with it?

disregard…feel stupid…


		set textCode to execute javascript "document.getElementById('FieldName').value;"

Hey There,

A lot of things seem simple after the fact, so don’t feel stupid “ just learn from it. :slight_smile:

Keep in mind that fields in a webpage may or may not be forms.


# Using the search field on http://www.macupdate.com
tell application "Safari"
	tell document 1
		# Set
		do JavaScript "document.getElementById('search_q').value = 'Find Any File'"
		# Get
		do JavaScript "document.getElementById('search_q').value"
	end tell
end tell


Chris


{ MacBookPro6,1 · 2.66 GHz Intel Core i7 · 8GB RAM · OSX 10.11.1 }
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯