Allow setting a timeout for clicking download buttons

This commit is contained in:
Manuel Thalmann 2024-08-18 09:04:42 +02:00
parent fccc0c2a7a
commit b4199c43a6

View file

@ -127,12 +127,16 @@ $null = New-Module {
.PARAMETER OutDir .PARAMETER OutDir
The directory to download the file to. The directory to download the file to.
.PARAMETER Timeout
The number of seconds to wait before clicking the download button.
#> #>
function Start-BrowserDownload { function Start-BrowserDownload {
param( param(
[string] $URL, [string] $URL,
[string] $ButtonSelector, [string] $ButtonSelector,
[string] $OutDir = $null [string] $OutDir = $null,
[double] $Timeout = 0
) )
Start-CustomBrowserDownload @PSBoundParameters -Action { Start-CustomBrowserDownload @PSBoundParameters -Action {
@ -153,8 +157,12 @@ $null = New-Module {
} }
} }
if ($Timeout -gt 0) {
Start-Sleep $Timeout;
}
if ($element) { if ($element) {
$Browser.FindElement([OpenQA.Selenium.By]::CssSelector($ButtonSelector)).Click(); $Browser.FindElement($selector).Click();
} else { } else {
Write-Error "Unable to find download button!"; Write-Error "Unable to find download button!";
} }