I'm trying to have puppeteer click the anchor which has a child span that contains certain text.
HTML snippet (with personal details removed by "..."):
<a data-url="/accounts/inquiry/accountdetails/..." class="account-title-group column " tabindex="0" role="link"> <i class="icon acct-tile checking"></i> <span class="account-name OneLinkNoTx" lang="en"> Checking</span> <span class="masked-account-number has-wells-advisor"> <span class="OneLinkNoTx">...</span> </span> </a> I've tried several variations to no avail:
//const aElementsWithChecking = await page.$x("//a[contains(., 'Checking')]"); //const aElementsWithChecking = await page.$x("//a[@class='account-title-group' and descendant::span[contains(., 'Checking')]]"); //const aElementsWithChecking = await page.$x("//a[@class='account-title-group' and descendant::span[contains(text(), 'Checking')]]"); //const aElementsWithChecking = await page.$x("//a[@class='account-title-group' and .//*[contains(text(), 'Checking')]]"); //const aElementsWithChecking = await page.$x("//a[@class='account-title-group' and .//*[contains(., 'Checking')]]"); const aElementsWithChecking = await page.$x("//a[(.//*|.)[.='Checking']]"); if (aElementsWithChecking.length > 0) { await aElementsWithChecking[0].click(); } else { throw new Error("Link not found"); } https://stackoverflow.com/questions/66512045/puppeteer-click-anchor-containing-a-span-with-matching-text March 07, 2021 at 08:20AM
没有评论:
发表评论