TypeError: Cannot read property 'click' of null

前端 未结 4 2014
[愿得一人]
[愿得一人] 2020-12-17 20:18

I have been mass following / unfollowing / favoriting / unfavoriting on twitter with these codes ;

$(\'button.follow-button\').click();
$(\'button.ProfileTwe         


        
相关标签:
4条回答
  • 2020-12-17 20:29

    In my case there was a conflict between jquery and another library so I had to implement a jQuery.noConflict(); in a script before calling in my main script.

    You could read more about jquery conflict here

    0 讨论(0)
  • 2020-12-17 20:31

    I had encountered this problem, when I run javascript on the webpage from elsewhere (eg. Selenium) while simultaneously using Developer Tools. Try closing Developer Tools and run the script.

    0 讨论(0)
  • 2020-12-17 20:37

    In my case the solution was to simply turn off the element-inspector within my browser! :)

    0 讨论(0)
  • 2020-12-17 20:40

    In order to use the jQuery library, you need to make sure that the library has been loaded on the page. As @adeneo mentioned, jQuery does not return null values, which means the $ variable is holding reference to an object that isn't jQuery. To verify that jQuery is loaded on a page, enter typeof jQuery into the chrome debugger. If jQuery is loaded on the page, the console will output "function". Otherwise, it will output "undefined". Steps for adding jQuery to your page can be found here.

    Once you have verified that jQuery is properly loaded on the page, you will have to correct the CSS selector that you are using to access the desired element.

    $(".a.follow") means "select all elements that have both classes 'a' and 'follow'".

    <div class="a follow"></div>

    Instead, your selector should be $("a.follow"), which means "select all 'a' type elements that have the 'follow' class".

    <a class="follow"></a>
    0 讨论(0)
提交回复
热议问题