On selecting the correct element to submit...

Hello, First time poster here.

I’m trying to select the correct element to submit with a javascript command.

Here is the piece of code representing that. This code allows me to select the correct element, but sometimes the order changes within the table… :


tell application "Google Chrome"
	tell window 1
		tell tab 1
			execute javascript "document.getElementsByTagName('form')[2].submit()"
		end tell
	end tell
end tell

Here is a sample of the html (there are multiple td elements with form tag elements within them)

The button i want to submit is value=“input3”, but it’s not always there. Some tables only have 1 or 2.

How can i use applescript to select the correct form tag within the correct table?

Please let me know if I need to clarify anything. Thanks.


tell application "Google Chrome"
	tell window 1
		tell tab 1
			set myTags to (execute javascript "document.getElementsByTagName('form'))[2].submit()"
			repeat with i from 1 to (count of myTags)
				set theTag to (item i of myTags) as text
				if theTag contains "value=\"input3\" class=\"managebtn\"" then return (item i of myTags)
			end repeat
			display dialog "NO FOUND APPROPRIATE TAG" buttons "OK"
		end tell
	end tell
end tell