【问题标题】:Use Google Chrome DevTools to click on the "Follow" buttons on the page使用 Google Chrome DevTools 点击页面上的“Follow”按钮
【发布时间】:2021-08-17 03:58:05
【问题描述】:

我当前的脚本:

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

【问题讨论】:

  • 您是否尝试过不使用 foreach 来查看选择器是否正常工作?

标签: javascript google-chrome-devtools devtools


【解决方案1】:

当您想要定位包含您指定的所有类的元素时,您需要用点分隔类名。例如:

<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-classanother-classyet-another-class

【讨论】:

    猜你喜欢
    • 2021-11-25
    • 2016-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-15
    • 2016-08-02
    • 2021-08-22
    • 2017-05-04
    相关资源
    最近更新 更多