简体   繁体   English

如何在页面加载时单击按钮

[英]How to click a button when a page loads

Ive got to programmatically click a cookie accept button when a page loads.当页面加载时,我必须以编程方式单击 cookie 接受按钮。 I tried a few different addons that are showed online.我尝试了一些在线显示的不同插件。 Those did not work...那些没有用...

The button has the following code:该按钮具有以下代码:

<a id="acceptAllPrivacyOptionsAtag" class="bcGiveConsent bcpConsentButtonAtag bcpConsentOKButtonAtag" aria-label="accept all privacy options" role="button"> accept all cookies  </a>

Is there a way to do this in javascript?有没有办法在javascript中做到这一点? I have to execute the code in bash shell when the page loads.当页面加载时,我必须在 bash shell 中执行代码。

好吧,有一种叫做 Alert() 的东西,它在页面加载时会没事,但不是最好的选择。

Refering to this answer.参考这个答案。

Add a script tag at the bottom portion of your html code and trigger a click event manually.在 html 代码的底部添加一个脚本标记并手动触发点击事件。

document.getElementById('acceptAllPrivacyOptionsAtag').click()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM