I am using phantomJS, which doesn't seem to fire inline on[click/change/whatever] events by default when you interact with a DOM element - you need to get a reference to them and then invoke them explicitly like so;
var element = document.getElementById('myId');
element.dispatchEvent(new Event('click'));
Or like this:
var element = document.getElementById('myId');
if(element.onclick) element.onclick();
This is working fine for function calls without arguments but I have cases where the on[click/change/whatever] function call has some hardcoded parameters like so:
<input type="text" value="some val" onclick="someFunction('hardcodedString1', 'hardcodedString2')">
Where some function is just a function accepting two strings as parameters.
I know I can get a reference to the onclick function like this:
var click = element.onclick;
But how can I get a reference to the arguments too, or a reference to the function including the arguments so that I can just invoke it and it will behave exactly the same as when clicked in a browser?
Something like:
var click = element.onclick;
var argsList = element.onclick.args;
click(argsList);