I want to make Puppeteer click on some tabs based on the number of items in an array called tabs
:
;(async () => {
const browser = await puppeteer.launch({
headless: true
})
const page = await browser.newPage()
await page.goto(`https://www.example.com`)
const tabs = ['tab1', 'tab2', 'tab3']
tabs.forEach((tab, index) => {
await page.click(`.postab-container li:nth-of-type(${ index + 1 }) a`)
})
})()
But I get this error:
await page.click(`.postab-container li:nth-of-type(${ index + 1 }) a`) ^^^^ SyntaxError: Unexpected identifier
It seems like the forEach
statement is messing up page
.
What's the correct way of doing this?