I have been trying to automate a process I do on a website with VBA but my knowledges of JavaScript are limited. I have asked things regarding this but haven't got a solution yet.
What I need to do is to answer a series of Y/N questions which work like this, for example the question has two more sub-questions related. If you choose 'Yes' in the first one the second one appears and so on. The thing is that I can't make the VBA to trigger all the events that website has meaning I can answer 'Yes' to the second question (the first is always already answered manually when I start working) now it won't show the third and last question.
I have looked at the JS code and as I dig more in it I keep finding things. So far I know from debugging on the browser that there is a 'mousedown' event on the document triggered by the second answer element name that shows the options Y/N, then another event 'change' that comes from a div element that boxes the second questions paragraph.
change event
on the right panel are the properties of the argument
Regarding VBA and trying to trigger the event I have tried a lot things now..
.fireEvent
"onchange" or "onclick" won't work
.iedoc.parentWindow.execScript
and the function eventHandle()
gives error.
This is the function in JS
elemData.handle = eventHandle = function() {
// Handle the second event of a trigger and when
// an event is called after a page has unloaded
return typeof jQuery !== "undefined" && !jQuery.event.triggered ?
jQuery.event.handle.apply( eventHandle.elem, arguments ) :
undefined;
};
This doesn't give error but nothing happens either:
Dim event_onChange As Object
Set event_onChange = ieDoc.createEvent("HTMLEvents")
While ieApp.Busy Or ieApp.readyState <> 4: DoEvents: Wend
ieDoc.querySelector("select[name='meetingQuestionAnswer(221010)']").Focus
event_onChange.initEvent "mousedown", True, False
ieDoc.querySelector("select[name='meetingQuestionAnswer(221010)']").dispatchEvent event_onChange
event_onChange.initEvent "change", True, False
ieDoc.querySelector("select.auto-save[name='meetingQuestionAnswer(221010)']").dispatchEvent event_onChange
ieDoc.querySelector("select.auto-save[name='meetingQuestionAnswer(221010)']").Value = "Yes"
the event should be dispatched from the target element or the currentTarget element? or how could I trigger the events to show the Y/N option box and to load the other question?