Automating Chrome with AutoHotkey Script to Handle EventListeners & custom edit fields
Notes on handle EventListeners & custom edit fields
00:09 When web scraping, often there will be buttons I can’t press, text that doesn’t get “acknowledged” that it has been entered, etc. Continue reading
Today’s AutoHotkey Webinar on Advanced Web Scraping with AutoHotkey we covered some “fun” topics. We also demonstrated using Visual Events 2 to detect Event Listeners on a page
; Stupid simple webScraping with AutoHotkey
Send, ^a ;Select All
sleep, 50
Send, ^c ;copy
sleep, 50
Clipboard:=StrSplit(Clipboard,”:”).1 ;split the clipboard on the colon and return everything to the left of the first one
Send, ^v ;paste
sleep, 350
Send, {tab 4} ;tab to the next field where I need to re-run
We also showed a bit about dealing with Try and using .item[0] in the DOM call. i.e. instead of using
pwb.document.getElementsByClassName(“feed”)[0].InnerText
use
pwb.document.getElementsByClassName(“feed”).item[0].InnerText
This way, if an element doesn’t exist, it will not error out.
To wait for it to be present you could do this
while (pwb.document.getElementsByClassName(“feed-identity-module__stat link-without-visited-state”).length < 3){
ToolTip, Here
Sleep, 50
Cap’n Odin offered up these two gems. The first will close all running AutoHotkey scripts and the second one will pause them.
; Close all AutoHotkey scripts
DetectHiddenWindows On
Winget, lst, List, ahk_exe autohotkey.exe
You ever plugging along on web scraping a page and have a problem with an element (drop down, edit field, radio button, etc) not updating? Chances are the page has an EventListener watching that element for a specific Event type. We used to be able to reliably “click” an element or send .fireEvent(“onchange”) / .fireEvent(“onclick”) however more and more pages are using this newer approach where they build an Event Listener and monitor for events on a given element.
If you’re not a programmer (like me), this was very problematic to deal with as the EventListener is located in a different place in the DOM. In the below video I walk through how to spot the problem and offer up a couple of solutions (like Visual Event) that should greatly help. The second video below demonstrates using my updated AutoHotkey syntax writer.
Triggering an EventListener on a page
Updated AutoHotkey Syntax Writer
Here I demonstrate using my updated AutoHotkey Syntax writer to provide the needed information for the Events.