Filling online forms on chrome/mozilla/edge

Get help with using AutoHotkey and its commands and hotkeys
alexandremuniz
Posts: 1
Joined: 07 Mar 2018, 12:18

Filling online forms on chrome/mozilla/edge

07 Mar 2018, 13:15

Hello all,

I'm trying to fill in an online form automatically with data extracted from an excel sheet. So I put the contents of the cells I want in variables inside my script. Then I activate the browser window by clicking on its icon on the taskbar (the browser is already running, and on the website I want). Then click on each box on the browser window that I want to fill and use SendRaw to fill it. The code that does this is pasted below.


Code: Select all

#SingleInstance force ;If this script is already running, terminate it and load a new instance
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

^+3::
CoordMode, Mouse, Screen
Sleep, 200
Xl := ComObjActive("Excel.Application") ;creates a handle to your currently active excel sheet
var1 := Xl.ActiveCell.text
var2 := Xl.Range("R8").text
var3 := Xl.Range("S8").text
MsgBox, 4, , %var1% %var2% %var3%
IfMsgBox No
    return
Sleep, 200
MouseClick, left,  583,  1055 ; activates chrome window by clicking on the taskbar
Sleep, 200
WinWait, Plataforma - Google Chrome, 
IfWinNotActive, Plataforma - Google Chrome, , WinActivate, Plataforma - Google Chrome, 
WinWaitActive, Plataforma - Google Chrome, 
Sleep, 200
MouseClick, left,  0,  500 ;clicks on point on the screen with no buttons or fields
Sleep, 200
Send, {Home} ;rolls the page to the top
Sleep, 200
MouseClick, left,  1910,  1019  ;clicks the arrow down to roll the page so the input fields are visible
Sleep, 200
MouseClick, left,  1910,  1019
MouseClick, left,  1910,  1019
Sleep, 200
MouseClick, left,  1910,  1019
Sleep, 200
MouseClick, left,  1464,  657 
MouseClick, left,  1464,  657 ;double clicks on textbox 1
Send, {BASCKSPACE} ;erases contents of the textbox 1
Sleep, 200 
SendRaw, %var1%
Sleep, 200 
MouseClick, left,  1464,  737 
MouseClick, left,  1464,  737 ;double clicks on textbox 2
Sleep, 200
Send, {BASCKSPACE} ;erases contents of the textbox 2
Sleep, 200
SendRaw, %var2%
Sleep, 200
MouseClick, left,  1620,  737 
MouseClick, left,  1620,  737 ;double clicks on textbox 3
Sleep, 200
Send, {BASCKSPACE} ;erases contents of the textbox 3
Sleep, 200
SendRaw, %var3%
Sleep, 200
MouseClick, left,  1510,  580 ; clicks button
Sleep, 200
Return


My problem is that, sometimes this script works like a charm. Other times, some of the fields are filled incorrectly. The filling errors I get running the exact same code, on the same machine, are described below:
- One of the fields is not filled. I can see that the script clicks on the right box, but the information somehow is not pasted into it;
- One of the fields is filled correctly, but shortly after (less than a second, usually when the script is filling some other field), it becomes empty again;
- One of the fields are filled, but with one character of the string missing. For example, I want to paste "5000" but the script sends "500", or "000".

After testing the exact same script some dozens of times, I came to the conclusion that these errors are completely random. I have no way of knowing if the data is going to pasted correctly or not. About half of the times I run it, it works perfectly, sometimes 5 or 6 times in a row, the other times it fails. I have tried switching from SendMode,Input to SendMode,Event, and also tried changing the sleep time between commands from 100 to 1000, to no avail.

Naturally, every time I fill in the form manually, none of these errors happen.

Can someone shed a light on this one?

Thanks

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, Bing [Bot], Google [Bot], Herchi, Mipha, Sabestian Caine and 72 guests