web automation framework playwright

Reference: Basic usage of Playwright, an emerging crawler tool | Jingmi (cuiqingcai.com) 

http://t.csdn.cn/S7260

Official documentation: Trace viewer | Playwright 

Install

pip3 install playwright

playwright install

first demo

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    for browser_type in [p.chromium]:
        browser = browser_type.launch(headless=False)
        page = browser.new_page()
        page.goto('https://www.baidu.com')
        page.screenshot(path=f'screenshot-{browser_type.name}.png')
        print(page.title())
        browser.close()

Open the chrome browser, print out the title and take a screenshot, and close the browser.

Record build script

playwright codegen -o script.py -b firefox

The browser will be opened, and the script can be generated synchronously by operating directly in the browser. The script can be put into the py file and run directly in python

 Some common APIs such as clicking click, inputting fill and other operations, these methods belong to the Page object, so all the methods can be searched from the API documentation of the Page object, the document address: https://playwright.dev/python /docs/api/class-page.

playwright+pytest-advanced articles-demo combat 

http://t.csdn.cn/vGqGw

Guess you like

Origin blog.csdn.net/seanyang_/article/details/131176570