小编Oly*_*lya的帖子

如何使用 Playwright 打开新选项卡(例如,单击按钮在新选项卡中打开新部分)

我正在寻找针对当前情况的更简单的解决方案。例如,您打开 google(任何其他网站),并且希望通过单击按钮(例如 Gmail)- 使用 Playwright 在新选项卡中打开此页面。

let browser, page, context;
describe('Check the main page view', function () {
    before(async () => {
        for (const browserType of ['chromium']) {
            browser = await playwright[browserType].launch({headless: false});
            context = await browser.newContext();
            page = await context.newPage();
            await page.goto(baseUrl);
        }
    });
    after(async function () {
        browser.close();
    });
    
        await page.click(tax);
        const taxPage = await page.getAttribute(taxAccount, 'href');

        const [newPage] = await Promise.all([
        context.waitForEvent('page'),
        page.evaluate((taxPage) => window.open(taxPage, '_blank'), taxPage)]);

        await newPage.waitForLoadState();
        console.log(await newPage.title());
Run Code Online (Sandbox Code Playgroud)

javascript tabs webautomation node.js playwright

11
推荐指数
2
解决办法
3万
查看次数

标签 统计

javascript ×1

node.js ×1

playwright ×1

tabs ×1

webautomation ×1