Home > Back-end >  Hit particular refresh icon at a time interval [closed]
Hit particular refresh icon at a time interval [closed]

Time:09-23

I want to hit particular refresh icon in a web page with a specific time interval like 10sec, 20sec etc.

<img class="refreshIcon" src="/assets/images/refresh-icon.svg" alt="Refresh">

Is there any extension available to do this or something else to get the result?

CodePudding user response:

You can use getElementsByClassName to get the icon by class to click, then use setInterval to set a loop.

// Click icon
function goToActivityTab() {
    var icon = document.getElementsByClassName(".refreshIcon")[0];
    icon.click();
}

// Repeat click
setInterval(function() {
  goToActivityTab();
}, 20000); // 20000 milliseconds (20 seconds)

CodePudding user response:

The best option is to use a setInterval(), this allows you to run a piece of code indefinitely using a specified interval. See the docs here for more info on setInterval()

setInterval(() => {
  location.reload()
}, 10000); // time in ms

Edit: changed to location.reload() instead of clicking on the image.

  • Related