I have an element like this.
Try to use onclick instead of click.
onclick
click
document.querySelector("g#box_w").onclick();
Remember that what we are doing here is calling the interface of the shape. So onclick needs to be defined in svg as it is in the question: