web自动化框架playwright

参考:新兴爬虫利器 Playwright 的基本用法 | 静觅 (cuiqingcai.com) 

http://t.csdn.cn/S7260

官方文档:Trace viewer | Playwright 

安装

pip3 install playwright

playwright install

第一个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()

打开chrome浏览器,打印出title并截图,关闭浏览器。

录制生成脚本

playwright codegen -o script.py -b firefox

会打开浏览器,直接在浏览器中进行操作,就能同步生成脚本,脚本放入py文件直接python可运行

web自动化框架playwright_第1张图片

 常见的一些 API 如点击 click,输入 fill 等操作,这些方法都是属于 Page 对象的,所以所有的方法都从 Page 对象的 API 文档查找就好了,文档地址:https://playwright.dev/python/docs/api/class-page。

playwright+pytest-进阶篇-demo实战 

http://t.csdn.cn/vGqGw

你可能感兴趣的:(#,web自动化selenium,自动化)