Automation.Playwright 1.57.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Automation.Playwright --version 1.57.0
                    
NuGet\Install-Package Automation.Playwright -Version 1.57.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Automation.Playwright" Version="1.57.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Automation.Playwright" Version="1.57.0" />
                    
Directory.Packages.props
<PackageReference Include="Automation.Playwright" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Automation.Playwright --version 1.57.0
                    
#r "nuget: Automation.Playwright, 1.57.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Automation.Playwright@1.57.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Automation.Playwright&version=1.57.0
                    
Install as a Cake Addin
#tool nuget:?package=Automation.Playwright&version=1.57.0
                    
Install as a Cake Tool

PlaywrightAutomation

PlaywrightAutomation 是一个为 .NET 应用封装的 Playwright 库,便于通过依赖注入与托管服务在应用中执行浏览器自动化 / 测试任务。

安装

dotnet add package Haessen.PlaywrightAutomation --version 1.57.0

快速开始(示例)

下面示例展示了典型的注册与使用方式,基于 Program.cs / Startup.cs 和一个控制器示例。

Program.cs(或 Startup.cs):

var builder = WebApplication.CreateBuilder(args);

// 注册 Playwright 服务
builder.AddPlaywrightDefaults();
builder.Services.AddControllers();

var app = builder.Build(); 
app.MapControllers(); 
app.Run();

示例控制器:


[ApiController]
[Route("[controller]/[action]")]
public class PlaywrightController(
    ILogger<PlaywrightController> logger,
    IPlaywrightService playwrightService) : ControllerBase
{
    #region 获取元素

    /// <summary>
    /// 获取指定 URL 的元素列表
    /// </summary>
    /// <param name="url">目标 URL</param>
    /// <param name="selector">CSS 选择器</param>
    /// <param name="attribute">属性名称(如 href 或 text)</param>
    /// <returns>元素列表</returns>
    [HttpGet]
    public async Task<IActionResult> GetElementList(string url, string selector, string attribute)
    {
        try
        {
            var result = await playwrightService.GetElementList(url, selector, attribute);
            return Ok(result);
        }
        catch (Exception ex)
        {
            logger.LogError(ex, "获取元素列表失败");
            return StatusCode(500, $"获取元素列表失败: {ex.Message}");
        }
    }

    /// <summary>
    /// 获取指定 URL 的元素内容
    /// </summary>
    /// <param name="url">目标 URL</param>
    /// <param name="selector">CSS 选择器</param>
    /// <param name="attribute">属性名称(如 html 或 text)</param>
    /// <returns>元素内容</returns>
    [HttpGet]
    public async Task<IActionResult> GetElement(string url, string selector, string attribute)
    {
        try
        {
            var result = await playwrightService.GetElement(url, selector, string.Empty, attribute);
            return Ok(result);
        }
        catch (Exception ex)
        {
            logger.LogError(ex, "获取元素内容失败");
            return StatusCode(500, $"获取元素内容失败: {ex.Message}");
        }
    }
    #endregion

}

文档与仓库

更多文档请参见仓库主页:https://github.com/haessen1998/PlaywrightAutomation

许可证

本项目使用 MIT 许可证(详见 LICENSE.txt)。

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.58.2 125 5/22/2026
1.58.1 106 5/20/2026
1.58.0 142 2/27/2026
1.57.2 133 1/29/2026
1.57.1 124 1/28/2026
1.57.0 143 1/28/2026 1.57.0 is deprecated because it is no longer maintained.

首次发布