admin管理员组

文章数量:1355600

I am trying to programmatically click a button in a web page using the mand

document.getElementsByName("versionFile")[0].click()

while this mand 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.

I am trying to programmatically click a button in a web page using the mand

document.getElementsByName("versionFile")[0].click()

while this mand 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.

Share Improve this question edited Jan 27, 2022 at 23:48 QHarr 84.5k14 gold badges56 silver badges104 bronze badges asked Jan 25, 2022 at 11:35 KarnanKarnan 211 gold badge1 silver badge2 bronze badges 2
  • What does vba have to do with this? – QHarr Commented Jan 25, 2022 at 17:58
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Bot Commented Feb 3, 2022 at 10:32
Add a ment  | 

2 Answers 2

Reset to default 2

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.

As of latest years, this is no longer working :

Chrome shows for such operations :

No js can do this anymore

本文标签: