PrivateFunctions/Get-Puppeteer_EnterVariableIntoSelector.ps1

<#
.SYNOPSIS
    This function returns the Node JS Puppeteer code for entering the value of a variable into a selector on a browser page.
#>

function Get-Puppeteer_EnterVariableIntoSelector {
    [CmdletBinding(PositionalBinding=$true)]
    [OutputType([String])]
    param (
        # The name of the selector.
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [String]$selectorName,

        # The name of the variable.
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [String]$variableName
    )

    # Generate the code
    $code = @"
selector = '%selectorName%';
await page.waitForSelector(selector);
await page.type(selector, %variableName%)
"@

    $code = $code -replace "%selectorName%", $selectorName
    $code = $code -replace "%variableName%", $variableName

    # Return the code
    return $code
}