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 {
|
$null = New-Module {
|
||||||
. "$PSScriptRoot/System.ps1";
|
. "$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
|
.SYNOPSIS
|
||||||
Runs an action involving browser automation.
|
Runs an action involving browser automation.
|
||||||
|
@ -14,13 +27,7 @@ $null = New-Module {
|
||||||
[scriptblock] $Action
|
[scriptblock] $Action
|
||||||
)
|
)
|
||||||
|
|
||||||
if (-not ("OpenQA.Selenium.Firefox.FirefoxDriver" -as [type])) {
|
Import-BrowserAutomation;
|
||||||
$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);
|
|
||||||
}
|
|
||||||
|
|
||||||
& $Action;
|
& $Action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,7 +109,7 @@ $null = New-Module {
|
||||||
$result;
|
$result;
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-Error "$Error";
|
Write-Error $_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,7 +133,7 @@ $null = New-Module {
|
||||||
function Start-BrowserDownload {
|
function Start-BrowserDownload {
|
||||||
param(
|
param(
|
||||||
[string] $URL,
|
[string] $URL,
|
||||||
[string] $ButtonSelector,
|
$ButtonSelector,
|
||||||
[string] $OutDir = $null,
|
[string] $OutDir = $null,
|
||||||
[double] $Timeout = 0
|
[double] $Timeout = 0
|
||||||
)
|
)
|
||||||
|
@ -136,7 +143,12 @@ $null = New-Module {
|
||||||
[OpenQA.Selenium.Firefox.FirefoxDriver] $Browser
|
[OpenQA.Selenium.Firefox.FirefoxDriver] $Browser
|
||||||
)
|
)
|
||||||
|
|
||||||
$selector = [OpenQA.Selenium.By]::CssSelector($ButtonSelector);
|
if ($ButtonSelector -is [string]) {
|
||||||
|
$selector = [OpenQA.Selenium.By]::CssSelector($ButtonSelector);
|
||||||
|
} else {
|
||||||
|
$selector = $ButtonSelector;
|
||||||
|
}
|
||||||
|
|
||||||
[OpenQA.Selenium.IWebElement] $element = $null;
|
[OpenQA.Selenium.IWebElement] $element = $null;
|
||||||
|
|
||||||
for ($i = 0; $i -lt 5; $i++) {
|
for ($i = 0; $i -lt 5; $i++) {
|
||||||
|
|
Loading…
Reference in a new issue