I mean, using
ControlClick and
ControlSend might also work, to a certain extent, if the browser is just in the background, but not minimized. I just tested this on a Firefox instance with a typical Google results page - and it filled the search field at the top:
Code: Select all
F1::
SetControlDelay -1
ControlClick x370 y145, ahk_exe firefox.exe ,,, 2, NA ; adjust coords!
ControlSend, , test, ahk_exe firefox.exe
return
The
Controlclick chose the website control based on position and then, leaving the control name out,
ControlSend just sent to the
topmost control of the chosen window (like described for
the first parameter in the docs). No idea, if that will work on any browser type or how reliable it really is. Of course, you can't really account for slight layout changes on the website or the the zoom level this way. Browser automation would give you more options, even for "headless" (not visible) browsers. (Although changes in the website's source code might also break your script.) But perhaps this is already sufficient for your specific use case.
Edit:
Example for Internet Explorer's COM interface (see, for example,
Joe Gline's videos; and many examples on this forum):
Code: Select all
ie := ComObjCreate("InternetExplorer.Application")
ie.visible := true
ie.Navigate("https://82187.csb.app/") ; mockup page for testing
; wait for the browser to load
while (ie.ReadyState != 4 or ie.Document.ReadyState != "complete" or ie.busy)
{
sleep 100
}
msgbox Click 'OK' to fill in zip code...
ie.document.getElementById("OZipCode").value := 44304
Please note that I put the HTML code you provided above into a "codesandbox" (
https://82187.csb.app), a website mockup, to be able to demonstrate the effect. You don't have to use it - you can try "your" website instead (but the code might fail, if there are
frames involved - there is no way to tell, based on the snippet you provided).
- zip search.png (2 KiB) Viewed 12261 times
(Currently, the button won't do anything.)
Edit2:
The same in Chrome (in debug mode), using
Chrome.ahk by GeekDude:
Code: Select all
#NoEnv
SetBatchLines, -1
SetTitleMatchMode 2
#Include Chrome.ahk ; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=42890
url := "https://82187.csb.app/" ; mockup page for testing
zip := 44304
; --- Create a new Chrome instance ---
FileCreateDir, ChromeProfile ; creates a profile subdirectory in current folder (on first start)
ChromeInst := new Chrome("ChromeProfile")
winwait, - Google Chrome
; --- Connect to the page ---
if !(Page := ChromeInst.GetPage( ))
{
MsgBox, Could not retrieve page!
ChromeInst.Kill()
}
else
Page.WaitForLoad()
Page.Call("Page.navigate", {"url": url}) ; Navigate to url
Page.WaitForLoad()
msgbox Click 'OK' to fill in zip code...
Page.Evaluate("document.getElementById('OZipCode').value = " zip)
return
Esc:: ; press Esc to exit script and Chrome instance
try ChromeInst.Kill()
ExitApp
Disclaimer:
Like always, use browser automation techniques in a reasonable manner; and at your own risk.