I’m trying to simulate a next page using playwright but I have to gather data first. The data per page only returns 50 posts. I need to get the first 150 post. The first 50 i can get data but on the next post I’m having a hard time because of the for loop
because its not async. This is my approach:
const browser = await chromium.launch({headless: false});
const context = await browser.newContext();
const page = await context.newPage();
// go to Hacker News
await page.goto("localhost:3000/posts");
// This data only returns the first 50 posts
const data = await page
.getByRole("table")
.nth(2)
.locator("tbody")
.locator(".age")
.all();
const strings = [];
for (const row of data) {
strings.push(await row.innerText());
console.log(await row.innerText());
}
await page.locator(".morelink").click({clickCount: 2, delay: 5}); <-- after click I wanted to run the `const data = await page...` code again 2 times to get the first 150.
console.log(strings);
I’m not familiar with playwright so I’m trying to figure out if there’s a way to chain locator and simulate click.