简体   繁体   English

通过浏览器中的控制台单击使用 javascript 的按钮

[英]Click a button using javascript via console in browser

I'm trying to click a specific button on a page using javascript by typing the javascript code into chrome console.我正在尝试通过在 Chrome 控制台中输入 javascript 代码来单击使用 javascript 的页面上的特定按钮。 It doesn't work.它不起作用。 Is it possible that the website can disable clicking an element via Javascript?网站是否可以通过 Javascript 禁用单击元素?

I've tried to call all button with a specific class to a variable, and then used the.click() method on a specific point.我尝试将具有特定 class 的所有按钮调用到变量,然后在特定点上使用 .click() 方法。

var zz = document.getElementsByClassName("red_buttons");
zz[0].click();

Ideally this would cause the page to act in the same way as a regular mouse click (which actually works), but it does absolutely nothing as far as I know.理想情况下,这会导致页面以与常规鼠标单击相同的方式运行(实际上有效),但据我所知,它绝对没有任何作用。

You can use this code to click on a specific button on the page.您可以使用此代码单击页面上的特定按钮。 In the section, you should type the ID value of the button you want to click.在该部分中,您应该键入要单击的按钮的 ID 值。 You can desing the clickfunc() function in any flexibility you want.您可以以任何您想要的灵活性设计 clickfunc() function。 It will be enough for you to just type the button.click();只需键入 button.click(); 就足够了。 statement into the function and it will click with the simplest version.声明到 function 中,它将点击最简单的版本。

var button = document.getElementById('<ElementID>');

function sleep(ms) {
      return new Promise(resolve => setTimeout(resolve, ms));
   }

async function clickfunc(){
    while(true){
        button.click();
        console.log("Tried. Next one in 10 sec.");
        await sleep(10000);
       }
  }

clickfunc();

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

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