-3

I'm new to scripting and i'm want to create a script so that it automatically clicks an "Add to Cart" button on the webpage once I visit it

HTML CODE IN THE BUTTON IS

<div id="gb_atc_e0c344b8" class="a-section a-spacing-small a-visible">
<div class="a-button-stack">
<span class="a-button a-spacing-none a-button-primary a-button-icon" id="a-autoid-0">
<span class="a-button-inner">
<i class="a-icon a-icon-cart"/>
<button title="Add to Shopping Cart" class="a-button-text a-text-null" type="button" id="a-autoid-0-announce">Add to Cart</button>
</span>
</span>
</div>
</div>

I've tried using the following script but none of them working If someone could help me create a script that would automatically click the add to cart button I would be extremely grateful


setInterval(function() {
    $('.a-text-null').trigger('click');
}, 10);

setInterval(function() {
   $("#a-autoid-0-announce").trigger('click');
}, 10);

setInterval(function() {
     $('.a-text-null').trigger('click');
}, 10);

setInterval(function() {
     $("#a-autoid-0-announce").trigger('click');
}, 10);

  • is not `click()` function working? – Shaiful Islam Jan 23 '15 at 13:29
  • 6
    Why the hell would you want to click that button every 10ms? – Sirko Jan 23 '15 at 13:30
  • Where is the function for the button itself? – putvande Jan 23 '15 at 13:31
  • @Sirko To boost sell rating, i guess... – A. Wolff Jan 23 '15 at 13:31
  • 1
    Seriously, this is obviously a XY problem. Ask specific question regarding your former issue, not the fix you think would work – A. Wolff Jan 23 '15 at 13:33
  • 1
    How exactly have you confirmed that none of these approaches are "working"? When you debug this, does the code execute at all? Does it repeat at the desired interval? Does the jQuery selector find the element(s) you're looking for? Is there even a click handler to be invoked? – David Jan 23 '15 at 13:33
  • no it is for ordering product in a flash sale as it lasts only for 2 to 3 seconds – Chaitanya Jan 23 '15 at 13:33
  • possible duplicate of [What's the easiest way to call a function every 5 seconds in jQuery?](http://stackoverflow.com/questions/2170923/whats-the-easiest-way-to-call-a-function-every-5-seconds-in-jquery) – Sadikhasan Jan 23 '15 at 13:34
  • Your code look right but there is no click callback. I have check it in this bin http://jsbin.com/xeyapayale/1/edit?html,js,console,output – Himen Jan 23 '15 at 13:36
  • @David Any one of the code is not hitting the Add to cart button – Chaitanya Jan 23 '15 at 13:38
  • try on this website i'm this as reference http://www.amazon.in/dp/B00NTYJQM2/ref=gb1h_img_m-2_3007_b78bdf33?smid=A14UQ4H17XUX90&pf_rd_m=A1VBAL9TL5WCBF&pf_rd_t=101&pf_rd_s=merchandised-search-2&pf_rd_r=19DPX3D3MYEYNA0EAF3D&pf_rd_i=4192584031&pf_rd_p=578443007 – Chaitanya Jan 23 '15 at 13:40
  • @Chaitanya: Did *you* try on that website? Because when I try I get a *very specific* error message. `"$ is not a function"` You need to load the jQuery library before you can use it. – David Jan 23 '15 at 13:43
  • @David is their any other way to add to cart button without jQuery libraries – Chaitanya Jan 23 '15 at 13:48
  • @Chaitanya: Sure, you can trigger the click event. For example, http://stackoverflow.com/questions/2381572/how-can-i-trigger-a-javascript-event-click – David Jan 23 '15 at 13:50
  • @David As i'm new to coding i'm struggling to find solution for 5 hours. Ur help made me to solve within 5 minute Thank u very much – Chaitanya Jan 23 '15 at 13:59

2 Answers2

0
window.setInterval(function(){
  $("#a-autoid-0-announce").trigger('click');
}, 10);
dpfauwadel
  • 3,866
  • 3
  • 23
  • 40
0

As we can't see the complete code, make sure that you have attached event handlers to the elements as well, e.g.

$("a-autoid-0-announce").on("click", function(){
        // do something
});
Villager
  • 604
  • 6
  • 15
  • Here is the reference i'm using this page HTML code http://www.amazon.in/dp/B00NTYJQM2/ref=gb1h_img_m-2_3007_b78bdf33?smid=A14UQ4H17XUX90&pf_rd_m=A1VBAL9TL5WCBF&pf_rd_t=101&pf_rd_s=merchandised-search-2&pf_rd_r=19DPX3D3MYEYNA0EAF3D&pf_rd_i=4192584031&pf_rd_p=578443007 – Chaitanya Jan 23 '15 at 13:41