Use case 1 — collect text
Capture all right-panel link texts and assert the count before clicking the target link.
page.locator('a.list-group-item').allInnerTexts()
This dummy login page is built for practising allInnerTexts(), locator.all(), filter({ hasText }), and clicking a specific link from many similar links. Your target for the class exercise is the Forgotten Password link in the account panel.
a.list-group-item account links
footer a footer links
Forgotten Password target
const rightPanelLinks = await page.locator('a.list-group-item').allInnerTexts();
console.log(rightPanelLinks.length);
for (const linkText of rightPanelLinks) {
if (linkText === 'Forgotten Password') {
await page.getByText(linkText).first().click();
break;
}
}
const footerLinks = await page.locator('footer a').all();
for (const link of footerLinks) {
console.log(await link.innerText(), await link.getAttribute('href'));
}
Capture all right-panel link texts and assert the count before clicking the target link.
page.locator('a.list-group-item').allInnerTexts()
Filter from many account links and click the one that has exact visible text.
filter({ hasText: 'Forgotten Password' })
Collect every footer anchor, print its text and href, then validate important legal links.
page.locator('footer a').all()