Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

72
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda