Help with chrome.ahk and sending event

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
grimboto
Posts: 53
Joined: 09 Jul 2014, 19:20

Help with chrome.ahk and sending event

Post by grimboto » 18 Feb 2022, 18:05

Hey I have been Automating a website using COM and IE but they recently updated there website and now it doesn't display in IE anymore so I'm trying to convert my old script over to Chrome using chrome.ahk.

The website displays a list and has a filter input box that updates the list as you type in it. The Filter doesn't update if you just set the value of the input box with COM/Javascript.

In IE the below code would make it update

Code: Select all

;Filter field to search for properties
	AddressSearchField := WB.document.getElementById("filterInput")
	;filter properties with start of address 
	AddressSearchField.value := "test"
	
	;fire event to update search results.
	event := WB.document.createEvent("Event")
	event.initEvent("input", true, true)
	AddressSearchField.dispatchEvent(event)
I've tried the following code using Chrome.ahk but i can't get it to update.

Code: Select all

	PageInst.Evaluate("document.getElementById(""filterInput"").value = '" . "test" . "'") ;this succesfully sets the value
	
	
	JS := "var event = document.createEvent('Event');"
	. "event.initEvent('input',true,true);"
	. "document.getElementById(""filterInput"").dispatchEvent(event);"
	
	PageInst.Evaluate(JS) ; this doesn't update the list
I also tried focusing the input box and sending an enter but the enter doesn't seem to get through

Code: Select all

JS := "setTimeout(function(){ document.getElementById(""filterInput"").focus(); }, 500);"

PageInst.Evaluate(JS)

Send , {Enter}
I've tried entering the javascript directly into the chrome console and it doesn't work either.

if anyone has any ideas of what i could try i would be greatly appreciative.

thanks Grimboto

jekko1976
Posts: 97
Joined: 10 Oct 2014, 07:03

Re: Help with chrome.ahk and sending event

Post by jekko1976 » 22 Feb 2022, 11:37

i kinda solved in something like this way

Code: Select all

js=
				(
				ut = document.getElementById('foo');
				ut.value = 'bar'
				ut.dispatchEvent(new Event('input', { bubbles: true }));
				ut.dispatchEvent(new Event('change', { bubbles: true }));
				)

ch.Evaluate(js)
You want to use "bubbles" to fire the events on the node and all his childs

I got in this code launching on the devtools a funny command called monitorEvents.

Precisely this:

monitorEvents(document, "control")

When you launch this command, then click in your web page, it "should" appear (but not always) all the events passing by the page at the click.

Here you can find additional info about the monitorevents:

https://developer.chrome.com/docs/devtools/console/utilities/#geteventlisteners

Hope it helps

Post Reply

Return to “Ask for Help (v1)”