Google Chrome login script

Hi everyone

I’m new to the whole apple scripting so I hope someone can help me.

I have tried to create an applescript that opens Google Chrome and goes to a specific website and tries to login using a username and a password however nothing gets typed in the input fields on the website when executing the script.
Hope you can help me getting the script to work.


set loginurl to "http://marketsworld.com/"
set mylogin to "test@test.com"
set myPassword to "test"



tell application "Google Chrome"
	tell window 1
		tell active tab
			open location loginurl
		end tell
	end tell
	
	tell window 1
		tell active tab
			execute javascript ("document.forms.input.id.value = '" & mylogin & "'")
			execute javascript ("document.forms.input.id.value = '" & myPassword & "'")
			execute javascript "document.forms.input.submit.click()"
		end tell
	end tell
end tell

--<input class="input" id="user_login_email" name="user[email]" placeholder="E-MAIL" size="" --type="email" value="" autocomplete="off" style="cursor: auto;">

--<input autocomplete="off" class="input" id="user_login_password" name="user[password]" --placeholder="PASSWORD" size="" type="password">

The last two outcommented lines is just to let you know the tags of the different input fileds on the website.

Hello.
I don’t use Chrome, for browsing or scripting but I think the first javascript should look like this, and then you can use that as a template for the second one.

tell active tab
      execute javascript ("document.getElementById('user_login_email').value = '" & mylogin & "'")
end 

The last line, only need to use the submit() function. (no click() ). You’ll need the id of the form to make a line like this:

Lastly, when you have the separate javascript pieces working, then you can consolidate those into 1 by separating the javascript statements with semicolons.

Hmm didn’t work but thanks for trying to help me.
It just gives me the error code “Missing Value”

Here is the updated script:


set loginurl to "http://marketsworld.com/"
set mylogin to "test@test.com"
set myPassword to "test"



tell application "Google Chrome"
	tell window 1
		tell active tab
			open location loginurl
		end tell
	end tell
	
	tell window 1
		tell active tab
			execute javascript ("document.getElementById('user_login_email').value = '" & mylogin & "'")
			execute javascript ("document.getElementById('user_login_password').value = '" & myPassword & "'")
			execute javascript "document.forms['inputForm'].submit()"
		end tell
	end tell
end tell

-- Username: <input class="input" id="user_login_email" name="user[email]" placeholder="E-MAIL" size="" --type="email" value="" autocomplete="off" style="cursor: auto;">
-- Password: <input autocomplete="off" class="input" id="user_login_password" name="user[password]" --placeholder="PASSWORD" size="" type="password">
-- Submit: <input class="submit" name="submit" type="submit" value="sign in">

Hello.

This isn’t very fancy, but you should be able to rework it for chrome. This worked for me when replicating your script in Safari, apart from the fact that either the password or the email address isn’t valid (or both).

Be sure to keep the delay statement, it is there, to be sure that the page has loaded, before we start to feed the form with values.

set loginurl to "http://marketsworld.com/"
set mylogin to "test@test.com"
set myPassword to "test"



tell application "Safari"
	tell window 1
		tell current tab
			open location loginurl
			delay 4
			do JavaScript ("document.getElementById('user_login_email').value = '" & mylogin & "'")
			do JavaScript ("document.getElementById('user_login_password').value = '" & myPassword & "'")
			do JavaScript ("document.getElementsByClassName('submit')[0].click();")
		end tell
	end tell
end tell

Ok so now I’ve updated it with the following however I still don’t see the script typing anything into the input fields and I still get the error message “Missing Value”


set loginurl to "http://marketsworld.com/"
set mylogin to "test@test.com"
set myPassword to "test"



tell application "Google Chrome"
	tell window 1
		tell active tab
			open location loginurl
		end tell
	end tell
	
	delay 4
	
	tell window 1
		tell active tab
			execute javascript ("document.getElementById('user_login_email').value = '" & mylogin & "'")
			execute javascript ("document.getElementById('user_login_password').value = '" & myPassword & "'")
			execute javascript ("document.getElementsByClassName('submit')[0].click();")
		end tell
	end tell
end tell



Hello.

Then I think you should try increase the delay, and comment out the two last lines of execute javascript, so that you can see if the field gets any contents. You should also maybe try to click on the field manually once, if you can’t see the input fields, when the form loads.

I can’t help you if anything is wrong with the syntax for Chrome though. But the javascript worked here for me with Safari.