BATCH SCRIPT - Automating website login

Asked

Viewed 11,070 times

4

I have the goal to create a file . bat that automates my login on a given site.

I can open the site with . bat through the start Chrome.exe command "meusite.com", and would like to know how to create a script that double-press the key TAB and once the key ENTER.

An example of what I imagine it to be:

start chrome.exe "http://www.meusite.com"
teclado_automatico "{Alt}"
teclado_automatico "{Alt}"
teclado_automatico "{Enter}"
  • 1

    You can try a different approach with powershell, instead of opening the browser, make a request and pass the login and password in the body(post).

  • thanks for the @rray tip

  • After logging into the site, you need to do what?

  • only display the screen in fullscreen, will be only for display

3 answers

3

Another alternative would be to use tools such as Autoit or Autohotkey which are automation languages for the Windows system and have various features to simulate a user interaction.

Follow example using the Autoit:

#include <IE.au3>
' Abre o Internet Explorer
Local $oIE = _IECreate("www.meusite.com", 1)

' Aguarda o carregamento da página
_IELoadWait($oIE)

' Captura os elementos pelo id
Local $oUsuario = _IEGetObjById($oIE, "usuario")
Local $oSenha = _IEGetObjById($oIE, "senha")
Local $oBotao = _IEGetObjById($oIE, "btn")

' Define os valores
$oUsuario.value = "foo"
$oSenha.value = "bar"

' Simula um clique
_IEAction($oBotao, "click")

3

An example in VBS, with internet explorer that you can adapt :

Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.AppActivate "Internet Explorer"
Wscript.Sleep 1500
WshShell.SendKeys "{TAB}"
Wscript.Sleep 1500
WshShell.SendKeys "{TAB}"
Wscript.Sleep 1500
WshShell.SendKeys "{ENTER}"
Wscript.Sleep 1500

1

I believe that the most appropriate solution to your problem of automation of tasks related to a browser is to use tools made exactly for this. One of the best known is iMacros. It has plugin for Chrome and Firefox.

The iMacros has its own programming language and can also use Javascript for automations. I used in the company I work to facilitate the entry of Nfe (Electronic Tax Notes), while the integration with ERP (via web service), had not been made.

Website: http://imacros.net/overview

Browser other questions tagged

You are not signed in. Login or sign up in order to post.