-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path04_multiwindow.py
More file actions
30 lines (23 loc) · 1021 Bytes
/
Copy path04_multiwindow.py
File metadata and controls
30 lines (23 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""04_multiwindow.py — clicking a target=_blank link surfaces a new Page.
Owl Light wires CEF's popup lifecycle into Playwright's auto-attach so
context.expect_page() resolves correctly for window.open / target=_blank.
"""
import asyncio
from playwright.async_api import async_playwright
async def main():
async with async_playwright() as p:
browser = await p.chromium.connect_over_cdp("http://localhost:9222")
ctx = browser.contexts[0]
page = ctx.pages[0]
await page.goto("https://the-internet.herokuapp.com/windows")
async with ctx.expect_page() as info:
await page.click('a[href="/windows/new"]')
new_page = await info.value
await new_page.wait_for_load_state("domcontentloaded")
h3 = await new_page.locator("h3").inner_text()
print(f"new tab url={new_page.url} h3={h3!r}")
assert h3 == "New Window"
await new_page.close()
await browser.close()
if __name__ == "__main__":
asyncio.run(main())