跳转到主要内容

Robocorp 浏览器自动化库

项目描述

robocorp-browser

robocorp-browser 包是针对 Playwright 项目的轻量级包装,具有诸如Playwright对象的生命周期管理自动化(旨在与 robocorp-tasks 一起使用)等生活品质改进。

用法

robocorp-browser

👉 确认您已在配置中添加了依赖项;此库不是robocorp捆绑包的一部分。

  • 用于自动化任务包conda.yaml
  • 用于自动化操作包的 package.yaml
  • 其余部分 requirements.txtpyproject.tomlsetup.py|cfg
from robocorp import browser, vault
from robocorp.tasks import task

@task
def automate_browser():
    """Start a browser to login in the surfed page."""
    # The configuration is used to set the basic `robocorp.browser` settings.
    # It must be called before calling APIs that create Playwright objects.
    browser.configure(
        # NOTE: `screenshot="only-on-failure"` is the default.
        # If this function finishes with an exception, it will make a screenshot and
        #  embed it into the logs.
        screenshot="only-on-failure",

        # By default, `headless` is False, unless running in a Linux container
        #  without a DISPLAY/WAYLAND_DISPLAY environment variable, but it
        #  can also be manually overridden.
        headless=True,  # won't display the browser window

        # Interactions may be run in slow motion (given in milliseconds).
        slowmo=100,
    )

    # The `browser.goto()` call may be used as a shortcut to get the current page and
    #  surf some URL (it may create the browser if not created already).
    browser.goto("https://example.com>")

    _login()  # call the login instructions


def _login():
    # APIs in `robocorp.browser` return the same browser instance, which is
    #  automatically closed when the task finishes.
    page = browser.page()

    # `robocorp.vault` is recommended for managing secrets.
    account = vault.get_secret("default-account")

    # Use the Playwright Browser API as usual to interact with the web elements.
    page.fill('//input[@ng-reflect-name="password"]', account["password"])
    page.click("input:text('Submit')")

🚀 现在开始使用我们的模板

指南

API参考

探索我们的API,获取详细的文档。

变更日志

发布列表及其对应更改可在变更日志中找到。

项目详情


下载文件

下载您平台对应的文件。如果您不确定选择哪个,请了解安装包的更多信息。

源分布

robocorp_browser-2.3.4.tar.gz (12.1 kB 查看哈希值)

上传时间

构建分布

robocorp_browser-2.3.4-py3-none-any.whl (14.2 kB 查看哈希值)

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面