gpt4 book ai didi

playwright - 如何检查是否已收到 Playwright 的回复?

转载 作者:行者123 更新时间:2023-12-05 04:29:59 30 4
gpt4 key购买 nike

使用 Java,我正在尝试等待对我正在等待的 Javascript 脚本之一的响应。

我已经发现我可以使用 waitForResponse ,但是如果在我到达 waitForResponse 语句之前脚本已经完成加载,这会导致出现问题。

有没有一种方法可以等待脚本完成,但前提是尚未收到脚本?

        page.waitForResponse("**/*<<Script reference>>*.js", () -> { });

如有任何帮助,我们将不胜感激!

最佳答案

您需要做的是审核所有流量。这里有一些例子:

import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;

public class Pw {
public static void main(String[] args) {
try (Playwright playwright = Playwright.create()) {
BrowserType chromium = playwright.chromium();
Browser browser = chromium.launch();
Page page = browser.newPage();
page.onResponse(response -> System.out.println(response.status() + " " + response.url()));
page.navigate("https://playwright.dev/java/docs/network");
browser.close();
}
}
}

输出:

200 https://playwright.dev/java/docs/network
200 https://playwright.dev/java/assets/css/styles.57a5681f.css
200 https://playwright.dev/java/js/redirection.js
200 https://playwright.dev/java/assets/js/main.bdc3f5b7.js
200 https://playwright.dev/java/assets/js/runtime~main.f37ee5cd.js
200 https://playwright.dev/java/img/playwright-logo.svg
200 https://playwright.dev/java/assets/js/04005ac5.4bff4e91.js

这样你就不会错过你的请求
希望对您有所帮助。

关于playwright - 如何检查是否已收到 Playwright 的回复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72202651/

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