Skip to content

Instantly share code, notes, and snippets.

@luizen
Last active June 7, 2025 22:06
Show Gist options
  • Save luizen/085c9ca515b94ad40cd81c4ce98ebd74 to your computer and use it in GitHub Desktop.
Save luizen/085c9ca515b94ad40cd81c4ce98ebd74 to your computer and use it in GitHub Desktop.
Click "Load More" button until no more items are available
const sleepNow = (delay) => new Promise((resolve) => setTimeout(resolve, delay));
async function repeatedLoadMore() {
for (let i = 1; i <= 50; i++) {
await sleepNow(5000);
console.log(`Iteration ${i}: Attempting to click the load more button...`);
var button = document.querySelector('a[data-testid=load-more-button]');
if (button) {
console.log("Button found, clicking it.");
button.click();
}
else {
var button2 = document.querySelector('a[data-testid=load-previous-button]');
if (button2) {
console.log("Button2 found, clicking it.");
button2.click();
}
else {
console.log("Button not found. Stopping the loop.");
break;
}
}
}
}
repeatedLoadMore()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment