【问题标题】:Playwright, how to leave iframe? Or why my elements are not visible剧作家,如何离开iframe?或者为什么我的元素不可见
【发布时间】:2023-02-14 02:41:35
【问题描述】:

我的问题是“如何访问 iframe 之外的其他元素”。\

        const frame = this.page.frame({name: "messagecontframe"});
        await expect(frame.locator(this.confirmationMessage)).toBeVisible();
        const bookingID = await frame.locator("(//td[@class='v1right'])[1]").innerText();
        await frame.locator(this.cancelBookingButton).click();

完成这些操作后,我需要导航到另一个 URL 并在另一个页面上做一些事情,但我什至无法点击某些东西,所有元素对我来说都是不可见的。我相信那是因为“我还在 iframe 中”。如何解决这个问题?有类似 iframe.leave 的东西吗?

【问题讨论】:

标签: playwright


【解决方案1】:

您需要做的是为您要在框架后单击的任何内容定义一个const你进入框架:

const fooButton = page.locator('bar');
const frame = page.frameLocator('iframe[title="baz"]')
...
// perform your actions on frame here
...
fooButton.click({ timeout: 1500000000 }); // I needed a very long timeout here

【讨论】:

    猜你喜欢
    • 2020-11-16
    • 1970-01-01
    • 1970-01-01
    • 2020-08-10
    • 2022-08-03
    • 1970-01-01
    • 2016-11-30
    • 1970-01-01
    • 2015-03-05
    相关资源
    最近更新 更多