I am trying to programmatically click a button in a web page using the command
document.getElementsByName("versionFile")[0].click()
while this command works fine in the developer tool console (opens the file selector) i am not able to execute this in script because it gives me a error saying "File chooser dialog can only be shown with a user activation" highlighting the click() function
Can anyone hep me out with this.
Most modern browsers restrict the JavaScript interactions not started by the user, to avoid annoying pages and make XSS a bit more difficult.
If you are using a web-scraping library like puppeteer, you should interact with the page using it's API (using page.click for example), not by injecting JavaScript on the page.
If that is not a option, you need to find the callback function that the button fires, and bypass the element.click() method.