使用剧作家有没有一种方法可以在特定框架内等待forselectorAsync?

发布于 2025-01-31 23:43:09 字数 711 浏览 2 评论 0原文

我写了几种扩展方法来简化这样的常见测试动作。

public static async Task WaitForElementToBeShown(this IPage page, string selector, int maxWaitInSeconds = 30, bool tolerateMultiples = true) {
            await page.WaitForSelectorAsync(selector, new PageWaitForSelectorOptions { State = WaitForSelectorState.Visible, Strict = !tolerateMultiples, Timeout = maxWaitInSeconds * 1000 });
        }

不幸的是,如果元素在框架中,这次是算出的。

有没有办法在特定框架内等待元素?

有没有办法等待元素不管其框架如何?

我知道我可以将以下内容包裹在循环中,然后等待它是真实的,但我希望剧作家已经实施了一些东西。

await _page.FrameLocator("frame locator").Locator("some selector").IsVisibleAsync();

我也认为,如果定位器不是唯一的话,这将引发例外。有没有办法使这条线可以容忍像WaitforselectorAsync方法一样?

I wrote a couple of extension methods to simplify common test actions like this.

public static async Task WaitForElementToBeShown(this IPage page, string selector, int maxWaitInSeconds = 30, bool tolerateMultiples = true) {
            await page.WaitForSelectorAsync(selector, new PageWaitForSelectorOptions { State = WaitForSelectorState.Visible, Strict = !tolerateMultiples, Timeout = maxWaitInSeconds * 1000 });
        }

Unfortunately this times out if the element is in a frame.

Is there a way to wait for an element inside a specific frame?

Is there a way to wait for an element to be shown regardless of it's frame?

I know I could wrap the following in a loop and wait for it to be true but I was hoping that playwright had implemented something already.

await _page.FrameLocator("frame locator").Locator("some selector").IsVisibleAsync();

also I think this will throw an exception if the locator isn't unique. Is there a way to make this line tolerate multiples like the WaitForSelectorAsync method?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文