在剧作家中设置饼干

发布于 2025-02-09 07:50:22 字数 165 浏览 1 评论 0原文

我在我正在测试的网站上有一个弹出窗口的窗口,我需要绕过它,我发现的最好方法是事先插入cookie,但我无法找到如何在此上完成此操作。剧作家 - 我已经搜索了一些搜索,但找不到我所追求的确切答案,从本质上讲,饼干只需要在击中URL之前就需要开火,以免出现尖叫声。

剧作家看不到框架不幸,否则我只需单击它。

I have a pop up "Do you agree to Cookies" window on a site I am testing and I need to bypass this, the best way I have found out is to insert a cookie beforehand, but I cannot find out how to do this on Playwright - I have done some searching around but can't find a definitive answer for what i am after, essentially the cookie just needs to fire before the URL is hit so the scream doesn't appear.

Playwright cannot see the frame unfortunatley, otherwise I would just click it..

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

携余温的黄昏 2025-02-16 07:50:22

使用 browser_conter_conter_context.add_cookies

我要假设要添加cookie的网站的域名 www.google.com ,cookie = value对是 hello-world

如果您使用异步Python:

chromium = playwright.chromium
browser = await chromium.launch(headless=False, devtools=True)
context = await browser.new_context()
await context.add_cookies([{'name': 'hello', 'value': 'world', 'domain': 'www.google.com', 'path': '/'}])

如果您的代码是同步的

chromium = playwright.chromium # or "firefox" or "webkit".
browser = chromium.launch(headless=False, devtools=True)
context = browser.new_context()
context.add_cookies([{'name': 'hello', 'value': 'world', 'domain': 'www.google.com', 'path': '/'}])

Use browser_context.add_cookies.

I am going to assume the domain of the site where you want to add cookies is www.google.com, and the cookie=value pair is hello-world.

If you are using asynchronous python:

chromium = playwright.chromium
browser = await chromium.launch(headless=False, devtools=True)
context = await browser.new_context()
await context.add_cookies([{'name': 'hello', 'value': 'world', 'domain': 'www.google.com', 'path': '/'}])

If your code is synchronous

chromium = playwright.chromium # or "firefox" or "webkit".
browser = chromium.launch(headless=False, devtools=True)
context = browser.new_context()
context.add_cookies([{'name': 'hello', 'value': 'world', 'domain': 'www.google.com', 'path': '/'}])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文