From 5a6d46153f2657100aaba45745a2b846602ca404 Mon Sep 17 00:00:00 2001 From: Manuel Thalmann Date: Sun, 18 Aug 2024 09:04:42 +0200 Subject: [PATCH] Allow setting a timeout for clicking download buttons --- scripts/Common/Scripts/BrowserAutomation.ps1 | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/Common/Scripts/BrowserAutomation.ps1 b/scripts/Common/Scripts/BrowserAutomation.ps1 index a7f93274..5806fee9 100644 --- a/scripts/Common/Scripts/BrowserAutomation.ps1 +++ b/scripts/Common/Scripts/BrowserAutomation.ps1 @@ -127,12 +127,16 @@ $null = New-Module { .PARAMETER OutDir The directory to download the file to. + + .PARAMETER Timeout + The number of seconds to wait before clicking the download button. #> function Start-BrowserDownload { param( [string] $URL, [string] $ButtonSelector, - [string] $OutDir = $null + [string] $OutDir = $null, + [double] $Timeout = 0 ) Start-CustomBrowserDownload @PSBoundParameters -Action { @@ -153,8 +157,12 @@ $null = New-Module { } } + if ($Timeout -gt 0) { + Start-Sleep $Timeout; + } + if ($element) { - $Browser.FindElement([OpenQA.Selenium.By]::CssSelector($ButtonSelector)).Click(); + $Browser.FindElement($selector).Click(); } else { Write-Error "Unable to find download button!"; }