ievjai

github
playwright Guide

API

提供同步(阻塞)API 和异步 API。它们在功能方面是相同的,并且仅在使用 API 的方式上有所不同。

from playwright import sync_playwright

with sync_playwright() as p:
    for browser_type in [p.chromium, p.firefox, p.webkit]:
        browser = browser_type.launch()
        page = browser.newPage()
        page.goto(\'http://whatsmyuseragent.org/\')
        page.screenshot(path=f\'example-{browser_type.name}.png\')
        browser.close()

async


import asyncio
from playwright import async_playwright

async def main():
    async with async_playwright() as p:
        for browser_type in [p.chromium, p.firefox, p.webkit]:
            browser = await browser_type.launch()
            page = await browser.newPage()
            await page.goto(\'http://whatsmyuseragent.org/\')
            await page.screenshot(path=f\'example-{browser_type.name}.png\')
            await browser.close()

asyncio.get_event_loop().run_until_complete(main())

自带pytest

def test_playwright_is_visible_on_google(page):
    page.goto("https://www.google.com")
    page.type("input[name=q]", "Playwright GitHub")
    page.click("input[type=submit]")
    page.waitForSelector("text=microsoft/Playwright")

https://playwright.dev/#version=v1.5.1&path=docs%2Fdebug.md&q=visual-studio-code-debugger

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-05-22
  • 2022-01-18
  • 2021-11-03
  • 2021-08-07
  • 2022-12-23
  • 2023-03-02
  • 2021-12-12
猜你喜欢
  • 2021-11-18
  • 2022-12-23
  • 2021-09-01
  • 2021-10-10
  • 2022-12-23
  • 2022-01-13
  • 2021-12-13
相关资源
相似解决方案