问题描述
我当前的脚本:
document.querySelectorAll('.components-button components-button-size-mini components-button-type-orange desktop components-button-inline').forEach(btn => btn.click());
我不明白为什么它不起作用,直到上周当我发送脚本并点击回车按钮时一切正常,现在这不再发生了。
我需要调整什么才能让它发挥作用?
网站链接:
https://booyah.live/users/42973126/followers
解决方法
当您想要定位包含您指定的所有类的元素时,您需要用点分隔类名。例如:
<div class="my-class another-class" />
document.querySelector('.my-class.another-class')
您拥有的是类为 .components-button
的某个元素,其中包含另一个元素名称为 components-button-size-mini
的元素,该元素包含另一个名称为 components-button-type-orange
的元素,依此类推。当然,在这个例子中,我不认为你有一个具有这样名称的实际元素。
因此要修复您的代码,请遵循我上面为选择器字符串提供的模式:
.some-class.another-class.yet-another-class
以上将针对具有指定的三个类的元素:some-class
、another-class
和 yet-another-class