Allow specifying any kind of button selector
This commit is contained in:
parent
3902fd7184
commit
05afb80c6d
1 changed files with 22 additions and 10 deletions
|
@ -2,6 +2,19 @@
|
|||
$null = New-Module {
|
||||
. "$PSScriptRoot/System.ps1";
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Imports the resources for using browser automation.
|
||||
#>
|
||||
function Import-BrowserAutomation {
|
||||
if (-not ("OpenQA.Selenium.Firefox.FirefoxDriver" -as [type])) {
|
||||
$packageRoot = Split-Path -Parent (Get-Package Selenium.WebDriver).Source;
|
||||
$file = Join-Path $packageRoot "lib/netstandard2.0/WebDriver.dll";
|
||||
$env:SE_MANAGER_PATH = Join-Path $packageRoot "manager" ($IsWindows ? "windows" : "linux") "selenium-manager$($IsWindows ? ".exe" : '')";
|
||||
$null = [System.Reflection.Assembly]::LoadFile($file);
|
||||
}
|
||||
}
|
||||
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Runs an action involving browser automation.
|
||||
|
@ -14,13 +27,7 @@ $null = New-Module {
|
|||
[scriptblock] $Action
|
||||
)
|
||||
|
||||
if (-not ("OpenQA.Selenium.Firefox.FirefoxDriver" -as [type])) {
|
||||
$packageRoot = Split-Path -Parent (Get-Package Selenium.WebDriver).Source;
|
||||
$file = Join-Path $packageRoot "lib/netstandard2.0/WebDriver.dll";
|
||||
$env:SE_MANAGER_PATH = Join-Path $packageRoot "manager" ($IsWindows ? "windows" : "linux") "selenium-manager$($IsWindows ? ".exe" : '')";
|
||||
$null = [System.Reflection.Assembly]::LoadFile($file);
|
||||
}
|
||||
|
||||
Import-BrowserAutomation;
|
||||
& $Action;
|
||||
}
|
||||
|
||||
|
@ -102,7 +109,7 @@ $null = New-Module {
|
|||
$result;
|
||||
}
|
||||
catch {
|
||||
Write-Error "$Error";
|
||||
Write-Error $_;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +133,7 @@ $null = New-Module {
|
|||
function Start-BrowserDownload {
|
||||
param(
|
||||
[string] $URL,
|
||||
[string] $ButtonSelector,
|
||||
$ButtonSelector,
|
||||
[string] $OutDir = $null,
|
||||
[double] $Timeout = 0
|
||||
)
|
||||
|
@ -136,7 +143,12 @@ $null = New-Module {
|
|||
[OpenQA.Selenium.Firefox.FirefoxDriver] $Browser
|
||||
)
|
||||
|
||||
if ($ButtonSelector -is [string]) {
|
||||
$selector = [OpenQA.Selenium.By]::CssSelector($ButtonSelector);
|
||||
} else {
|
||||
$selector = $ButtonSelector;
|
||||
}
|
||||
|
||||
[OpenQA.Selenium.IWebElement] $element = $null;
|
||||
|
||||
for ($i = 0; $i -lt 5; $i++) {
|
||||
|
|
Loading…
Reference in a new issue