Improve handling of slow websites

This commit is contained in:
Manuel Thalmann 2024-08-14 18:47:29 +02:00
parent 49a4e7332d
commit 771f7e2c00

View file

@ -90,18 +90,24 @@ $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);
$null = & $downloadAction -Browser $browser;
while (& $downloadChecker) { try {
Write-Host "Waiting for the download to finish…"; $null = & $downloadAction -Browser $browser;
Start-Sleep 1;
while (& $downloadChecker) {
Write-Host "Waiting for the download to finish…";
Start-Sleep 1;
}
$file = Get-ChildItem $dir;
$result = Move-Item $file $OutDir -PassThru;
$browser.Quit();
Remove-Item -Recurse $dir;
$result;
}
catch {
throw $Error;
} }
$file = Get-ChildItem $dir;
$result = Move-Item $file $OutDir -PassThru;
$browser.Quit();
Remove-Item -Recurse $dir;
$result;
} }
} }
@ -130,7 +136,24 @@ $null = New-Module {
[OpenQA.Selenium.Firefox.FirefoxDriver] $Browser [OpenQA.Selenium.Firefox.FirefoxDriver] $Browser
) )
$Browser.FindElement([OpenQA.Selenium.By]::CssSelector($ButtonSelector)).Click(); $selector = [OpenQA.Selenium.By]::CssSelector($ButtonSelector);
[OpenQA.Selenium.IWebElement] $element = $null;
for ($i = 0; $i -lt 5; $i++) {
$element = $Browser.FindElement($selector);
if ($element) {
break;
} else {
Start-Sleep 1;
}
}
if ($element) {
$Browser.FindElement([OpenQA.Selenium.By]::CssSelector($ButtonSelector)).Click();
} else {
throw "Unable to find download button!";
}
}; };
} }
}; };