Problem click a button using some JavaScript

I did this to make the button click on an icon on the site
The problem is that the button only works when I click anywhere on the site
When I press the button it doesn’t work
When I click anywhere on the page and then press the button it works
What solved the problem

4 posts were merged into an existing topic: How do I make a button that clicks on an icon in WebView