from playwright.sync_api import Playwright, sync_playwright, expect def run(playwright: Playwright) -> None: browser = playwright.chromium.launch(headless=False) context = browser.new_context() page = context.new_page() page.goto("https://oishi-kenko.com/recipes") page.get_by_text("ねぎたっぷり 塩牛丼").click() page.get_by_role("heading", name="ねぎたっぷり 塩牛丼").click() page.get_by_role("heading", name="ねぎたっぷり 塩牛丼").click(button="right") expect(page.get_by_role("article")).to_contain_text("ねぎたっぷり 塩牛丼") page.get_by_role("article").locator("li").filter(has_text="糖尿病").locator("div").click() expect(page.get_by_role("article")).to_contain_text("糖尿病") page.get_by_role("link", name="高血圧", exact=True).click() page.close() # --------------------- context.close() browser.close() with sync_playwright() as playwright: run(playwright)