Refactor browser scripts

This commit is contained in:
Manuel Thalmann 2024-08-08 03:32:03 +02:00
parent 29b0de86dc
commit b92173fa25
2 changed files with 5 additions and 3 deletions

View file

@ -52,6 +52,8 @@ $null = New-Module {
[string] $OutDir [string] $OutDir
) )
$downloadAction = $Action;
Start-BrowserAutomation { Start-BrowserAutomation {
if (-not $OutDir) { if (-not $OutDir) {
$OutDir = "."; $OutDir = ".";
@ -88,7 +90,7 @@ $null = New-Module {
$browser = [OpenQA.Selenium.Firefox.FirefoxDriver]::new($options); $browser = [OpenQA.Selenium.Firefox.FirefoxDriver]::new($options);
$browser.Navigate().GoToUrl($URL); $browser.Navigate().GoToUrl($URL);
& $Action -Browser $browser; $null = & $downloadAction -Browser $browser;
while (& $downloadChecker) { while (& $downloadChecker) {
Write-Host "Waiting for the download to finish…"; Write-Host "Waiting for the download to finish…";

View file

@ -134,12 +134,12 @@ $null = New-Module {
try { try {
& $download; & $download;
} catch { } catch {
$Browser.ExecuteScript("document.querySelector('$cookieBannerSelector').remove()"); $null = $Browser.ExecuteScript("document.querySelector('$cookieBannerSelector').remove()");
& $download; & $download;
} }
}; };
Start-Process -Wait -WorkingDirectory $dir -FilePath $file -ArgumentList "/S"; Start-Process -Wait -WorkingDirectory (Split-Path -Parent "$file") -FilePath "$file" -ArgumentList "/S";
Remove-Item -Recurse $dir; Remove-Item -Recurse $dir;
} }