0

This only refreshes the page once, I have tested it. How do I make it reload the page every 5 seconds and look for an element then click on it?

function reload() {
  document.location.reload();
}

setTimeout(reload, 5000);
john heroi
  • 47
  • 2
  • 12
  • 1
    [how-to-reload-page-every-5-seconds](https://stackoverflow.com/questions/2787679/how-to-reload-page-every-5-seconds) & [auto-click-button-element-on-page-load](https://stackoverflow.com/questions/18646881/auto-click-button-element-on-page-load-using-jquery) – Alon Adler Oct 07 '20 at 22:29
  • Whats your aim ? Do you want the page to keep reloading forever ? – Qudusayo Oct 07 '20 at 22:30
  • Yes, until the element is found setTimeout refreshes it once – john heroi Oct 08 '20 at 10:21

1 Answers1

1

Hopefully this is what you're looking for.

setTimeout(() => {
  const button = document.querySelector('.button');
  button.dispatchEvent(new MouseEvent('click'));
  window.location.reload();
}, 5000)
mmason33
  • 878
  • 1
  • 6
  • 10