gpt4 book ai didi

javascript - 如何使用 Playwright 打开新标签(例如单击按钮在新标签中打开新部分)

转载 作者:行者123 更新时间:2023-12-03 12:19:15 27 4
gpt4 key购买 nike

我正在寻找针对当前情况的更简单的解决方案。例如,您打开 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());

最佳答案

it('Open a new tab', async function () {
await page.click(button, { button: "middle" });
await page.waitForTimeout(); //waitForNavigation and waitForLoadState do not work in this case
let pages = await context.pages();
expect(await pages[1].title()).equal('Title');

关于javascript - 如何使用 Playwright 打开新标签(例如单击按钮在新标签中打开新部分),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64277178/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com