AutoHotkey tutorial – How to fill input fields on a website from a text file
In this AutoHotkey tutorial video, I will guide you through how you can fill the input fields on a website from a text file. The video covers the basics and could be useful for beginners since it’s really important how you can read a text file’s content.
It is useful to know how you can read text files and work with them. A commonly preferred text file format is CSV ( Comma Separated Values ). At the beginning of the video, I created a text file with dummy data. Then I showed how can the delimiter character be replaced. The old editor I used is AutoHotkey Studio, I started the project there. The next part was using FileRead. It is an important command that allows the user to read the text file’s content. It is followed by how actually reads AutoHotkey the text file using A_Index, and A_Loopfield commands. Then the field values of the file were assigned to variables and the script was finished.
; Script AutoHotkey tutorial - How to fill input fields on a website from a text file.ahk
; Author: Bence Markiel (bceenaeiklmr)
; Github: https://github.com/bceenaeiklmr/AutoHotkey-bookshelf/
; Date 01.05.2020
; #####################
#NoEnv
#SingleInstance, Force
SendMode, Input
SetWorkingDir, %A_ScriptDir%
SetTitleMatchMode, 2
return
F9::
FileRead, Input, % A_ScriptDir "\" "input.txt"
WinActivate, % "ahk_exe Chrome.exe"
WinWaitActive, % "ahk_exe Chrome.exe"
loop, Parse, Input, `n
{
; skip the header
if (A_index=1)
continue
; replace `n and split the into 'columns'
Line := StrReplace(A_LoopField, Chr(13))
Columns := StrSplit(Line, ";")
; assign variables
FirstName := Columns.1
LastName := Columns.2
Email := Columns.3
; fix phone number (space, plus, and minus chars)
RegExMatch(Columns.4, "\d+", Phone)
; click into the first field, some sleep is usually required
Click, 128, 170
Sleep, 100
; delete the field's content
Send, {Delete}
Sleep, 50
; send the values
Send, % FirstName "{Tab}" LastName "{Tab}" Email "{Tab}" Phone
Sleep, 10
}
return
The AutoHotkey commands I used in this short script:
- FileRead
- StrSplit, StrReplace
- Loop, A_index, A_LoopField
- WinActivate, WinWait
- Click, Send, SendInput
- Sleep
- RegexMatch
- Msgbox
In case you need the Html file to test the script just copy the following code and save it with the Html file extension.
<!DOCTYPE html>
<html>
<body>
<h3>Fields tester</h1>
<form action=”/action_page.php”>
<label for=”fname”>First name:</label>
<input type=”text” id=”fname” name=”fname”><br><br>
<label for=”lname”>Last name:</label>
<input type=”text” id=”lname” name=”lname”><br><br>
<label for=”email”>Email address:</label>
<input type=”text” id=”email” name=”email”><br><br>
<label for=”phone”>Phone number:</label>
<input type=”text” id=”phone” name=”phone”><br><br>
</form>
</body>
</html>
Fields tester
Leave A Comment