Find and fill in the input field with AutoHotKey

The task of all AutoHotKey masters:

Give us a function that will Find and move the cursor to the input field (like LoginName) and alternatively send the input text. For old, lazy hackers like me, just messing around with AHK, it would look like this:

FindFillField(*elementid*,*sendtext*,*alt-text*)

      

Where elementid

is the HTML id for the field, eg. USERNAME, where sendtext

is the text to be filled in and where alt-text

can be additional, specific text to help identify the fields.

Additional, optional parameters are always useful for rounding off odd cases, so get your fancy going!

For old-timers like me and everyone else, it would be a blessing when creating simple login macros.

+3


source to share


2 answers


You can always use the {TAB} parameter. Open the website and press the Tab key until you reach the input field and count how many times you hit it. Then do Send {TAB ##}. I used below to insert first name, middle name, last name and 2 other IDs into a web form. The variables were entered into the created graphical form.



Send {TAB 41}
Send %firstn%
Send {TAB}
Send %middle%
Send {TAB}
Send %lastn%
Send {TAB}
Send %deas%
Send {TAB}
Send %npis%
Send {TAB 3}
Send {N}
Send {TAB 2}
Send {ENTER}

      

+1


source


You can send text to the input field with the following code:

wb.document.getElementById("login-username").value := "myUserName"

      

Where wb

is the COM object, login-username

is the ID of the input field, and myUserName

is what you want to enter.

The entered identifier, you can also find the input field by name getElementsByName(...)

, tag getElementsByTagName(...)

name or class name getElementsByClassName(...)

. I found this tutorial to be helpful. Use Chrome or Firefox to find out how to define an input field (right click and click "validate item").



If you want to move the cursor to the input field then use

wb.document.getElementById("login-username").focus()

      

Here's a complete example using IE and the stack login page:

; Create IE instance
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := True
wb.Navigate("https://stackoverflow.com/users/login")
; Wait for page to load:
While wb.Busy or wb.ReadyState != 4
    Sleep, 100
; Press "Log in using Stack Exchange"
wb.document.getElementById("se-signup-legend").click()
While wb.Busy or wb.ReadyState != 4
    Sleep, 100
; EITHER focus on the input field:
wb.document.getElementsByName("email")[0].focus()
; OR send text directly to the field:
wb.document.getElementsByName("email")[0].value := "my@email.com"

      

+1


source







All Articles