Python 微软开源自动化工具 Playwright

1.安装依赖以及相应驱动

pip install playwright
python -m playwright install

2.参考示例

# -*- coding: utf-8 -*-
# @Time    : 2021/05/07 14:50
# @Author  : 

from playwright.sync_api import sync_playwright


def run(playwright):
    browser = playwright.chromium.launch(headless=False)
    # context = browser.contexts
    # Open new page
    page = browser.new_page()

    page.goto("https://www.baidu.com/")

    page.click('input[name="wd"]')

    page.fill('input[name="wd"]', 'jingdong')

    page.click('text="京东"')

    # 当前页面内容
    # html = page.content()
    with page.expect_navigation():
        with page.expect_popup() as popup_info:
            # normalize-space这个方法就可以去除文本中的前后空格和回车
            page.click("//a[normalize-space(.)='京东JD.COM官网 多快好省 只为品质生活']")

        # popup_info.value

    import time
    time.sleep(10)
    browser.close()


with sync_playwright() as playwright:
    run(playwright)

Python 微软开源自动化工具 Playwright_第1张图片

参考:https://pypi.org/project/playwright/
参考:https://www.imooc.com/article/314264

你可能感兴趣的:(个人学习记录,python,自动化测试)