I just wanted to share my first COM script after reading up on an awesome tutorial by Mickers
"Basic Ahk v1.1+ COM Tutorial for Webpages": - http://www.autohotkey.com/board/topic/6 ... -webpages/
MyScript is an example of browser automation using COM to navigate HTML DOM
This very basic example loads Google into a Gui window & then automates a search query.
Pointless I know but was just to prove concept.
Code: Select all
; COM_Google_Search.ahk
; by ameyrick.
;
google_query_string := "Site: www.w3schools.com JavaScript HTML DOM"
;
; A very basic example of browser automation using COM to navigate HTML DOM
; This example loads google into a Gui window & automates a search query.
;
; This is my first COM script after reading up on an awsome tutorial by Mickers
; "Basic Ahk v1.1+ COM Tutorial for Webpages"
; http://www.autohotkey.com/board/topic/64563-basic-ahk-v11-com-tutorial-for-webpages/
;
; DOM Documentation:
; http://www.w3schools.com/jsref/dom_obj_all.asp
#NoEnv
#SingleInstance Force
SetBatchLines -1
ListLines Off
ComObjError(False)
; =================================
; GUI
; =================================
Gui, Margin, 0, 0
Gui Add, ActiveX, w800 h600 vWB, Shell.Explorer ; web browser
ComObjConnect(WB, WB_events) ; Connect WB's events to the WB_events class object.
Gui, Show, w800 h600
; =================================
; Open url, and wait for page to finish loading
; =================================
OpenLoginPage:
WB.Navigate("http://www.google.co.uk")
While WB.readystate != 4 or WB.busy
Sleep 10
doc := WB.doc
sleep, 500
; =========================================
; search all "input" <tags> for the search bar & enter the query string
; =========================================
q := doc.getElementsByTagName("input") ;// get a list of all input tags
loop, % q.Length ;// loop through list of input tags
{
if ( q[(A_index-1)].title == "Search"){ ;// check the "title" attribute of the input tag
q[(A_index-1)].Value := google_query_string ;// enter the query string
sleep, 100
break
}
}
; ==========================================
; Submit the <form id="tsf"> to process our query
; ==========================================
doc.getElementByID("tsf").Submit() ;// Submit form "tsf"
return