2

I need to fill up a text field and click on a button on Google Chrome

Here is my script for safari.

tell application "Safari"

## tell window 1 of application "Safari" to set current tab to tab 1
-- Last Name
do JavaScript "document.getElementsByName('0.7.7.7.7.7.5')[0].value=" & quoted form of theProfil & "" in tab 1 of window 1
-- search
delay 0.1
do JavaScript "document.getElementsByName('0.7.7.7.7.1.7')[0].click();" in tab 1 of window 1

How can I use this (getElementsByName) with Chrome ?

cheers.

  • Is there a question here? – Allan Jan 5 '17 at 14:23
2

Google Chrome is scriptable through the Chromium suite—the execute method is what you're looking for. Here is an example of your code, re-written for Chrome:

tell application "Google Chrome"
    execute front window's active tab javascript  "document.getElementsByName('0.7.7.7.7.7.5')[0].value=" & quoted form of theProfil & ""
    delay 0.1
    execute front window's active tab javascript "document.getElementsByName('0.7.7.7.7.1.7')[0].click();"
end tell

See this question on Stack Overflow for reference, or consult the Google Chrome AppleScript dictionary (in Script Editor, click File > Open Dictionary… and choose Google Chrome).

  • that's perfect, I was looking for this for ages, thank you – Kevin Feb 17 '17 at 6:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .