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

View file

@ -134,12 +134,12 @@ $null = New-Module {
try {
& $download;
} catch {
$Browser.ExecuteScript("document.querySelector('$cookieBannerSelector').remove()");
$null = $Browser.ExecuteScript("document.querySelector('$cookieBannerSelector').remove()");
& $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;
}