单击页面上具有相同类Javascript的所有按钮 [英] Click all buttons on page with same class Javascript

查看:67
本文介绍了单击页面上具有相同类Javascript的所有按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试点击具有 btn btn-primary UnFollowUser 的页面上的所有按钮。

I'm trying to click all buttons on a page with the class "btn btn-primary UnFollowUser".

这是我尝试使用的脚本

var buttons = document.getElementsByName('UnFollowUser');

for(var i = 0; i <= buttons.length; i++)  
   buttons[i].click();

但这会引发错误:


VM336:5未捕获的TypeError:无法读取
的属性单击 undefined(…)(匿名函数)@ VM336:5InjectedScript._evaluateOn @
VM158:878InjectedScript._evaluateAndWrap @
VM158:811InjectedScript.evaluate @ VM158:667

VM336:5 Uncaught TypeError: Cannot read property 'click' of undefined(…)(anonymous function) @ VM336:5InjectedScript._evaluateOn @ VM158:878InjectedScript._evaluateAndWrap @ VM158:811InjectedScript.evaluate @ VM158:667

有什么想法吗?

推荐答案

您使用的是getElementsByName而不是 getElementsByClassName

You are using getElementsByName instead of getElementsByClassName

 var buttons = document.getElementsByClassName('UnFollowUser');

 for(var i = 0; i < buttons.length; i++)  
     buttons[i].click();

这篇关于单击页面上具有相同类Javascript的所有按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆