Javascript click() doesn't work on some elements
With yours help I found the solution:
var evt = document.createEvent('MouseEvents')
evt.initMouseEvent('mousedown', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
document.querySelectorAll('.tab-button')[0].dispatchEvent(evt)
Notice that it should be mousedown
event rather than click
. Some sites are done in a different way than others. Another important thing is 3rd parameter. It should be set to false
(in this particular case). It sets cancelable
value. Without this set to false
it doesn't work.
Thank you for all answers!
document.getElementsByClassName('tab-button')[0].dispatchEvent(event)
or
document.getElementsByClassName('tab-button')[0].fireEvent(event)
is the way you could do it... but trying it on the site, the 'click' event isn't bound to that element
EDITED See How to trigger event in JavaScript?