import { clickUntilExhausted } from "@intuned/browser";
import { BrowserContext, Page } from "playwright";
interface Params {}
export default async function handler(
params: Params,
page: Page,
context: BrowserContext
) {
await page.goto("https://sandbox.intuned.dev/load-more");
const loadMoreButton = page.locator("aside button"); // Select the button in the sidebar.
const container = page.locator(
'xpath=//*[@id="root"]/div[1]/main/slot/div/aside/div/div/slot/slot'
); // Watch the sidebar container to detect changes.
// This will count the elements under the container given before each click and after, if the count is the same, the function will stop.
let clickCount = 0;
await clickUntilExhausted({
page,
buttonLocator: loadMoreButton,
containerLocator: container,
heartbeat: () => {
clickCount++;
console.log(`Clicked ${clickCount} times`);
},
maxClicks: 30,
clickDelay: 0.5,
noChangeThreshold: 0,
});
// Will keep clicking the button until the button disappears or is disabled or the maxClicks is reached or no more content is loaded.
}