Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

69
Views
Applescript / Javascript unable to fill Safari input box

I have set my Safari homepage to a url that has a username and password form. My script should open Safari and set the username to a value. The script opens safari, the homepage is displayed, but no text added to input box.

tell application "Safari"
    activate
    tell window 1
        delay 3
        do JavaScript "document.getElementById('username').value = 'hello';"
    end tell
end tell

<input type="text" name="username" id="username" size="20" style="width: 150px;">

Can anyone suggest why?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to tell Safari where, e.g. tab n of window n or document n, etc.

Example AppleScript code:

tell application "Safari"
    tell current tab of window 1
        do JavaScript "document.getElementById('username').value = 'TheCoder';"
    end tell
end tell

Or:

tell application "Safari"
    do JavaScript "document.getElementById('username').value = 'TheCoder';" in document 1
end tell



Note: The example AppleScript code is just that and sans any included error handling does not contain any additional error handling as may be appropriate. The onus is upon the user to add any error handling as may be appropriate, needed or wanted. Have a look at the try statement and error statement in the AppleScript Language Guide. See also, Working with Errors. Additionally, the use of the delay command may be necessary between events where appropriate, e.g. delay 0.5, with the value of the delay set appropriately.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!