Ensure Selenium is imported
This commit is contained in:
parent
16f3c72eb3
commit
29b0de86dc
1 changed files with 38 additions and 36 deletions
|
@ -52,53 +52,55 @@ $null = New-Module {
|
||||||
[string] $OutDir
|
[string] $OutDir
|
||||||
)
|
)
|
||||||
|
|
||||||
if (-not $OutDir) {
|
Start-BrowserAutomation {
|
||||||
$OutDir = ".";
|
if (-not $OutDir) {
|
||||||
}
|
$OutDir = ".";
|
||||||
|
}
|
||||||
|
|
||||||
$dir = New-TemporaryDirectory;
|
$dir = New-TemporaryDirectory;
|
||||||
Write-Host "Downloading ``$URL`` using browser automation…";
|
Write-Host "Downloading ``$URL`` using browser automation…";
|
||||||
$options = [OpenQA.Selenium.Firefox.FirefoxOptions]::new();
|
$options = [OpenQA.Selenium.Firefox.FirefoxOptions]::new();
|
||||||
$options.SetPreference("browser.download.folderList", 2);
|
$options.SetPreference("browser.download.folderList", 2);
|
||||||
$options.SetPreference("browser.download.dir", "$dir");
|
$options.SetPreference("browser.download.dir", "$dir");
|
||||||
|
|
||||||
$downloadChecker = {
|
$downloadChecker = {
|
||||||
$files = Get-ChildItem $dir;
|
$files = Get-ChildItem $dir;
|
||||||
|
|
||||||
if ((@($files)).Count -gt 0) {
|
if ((@($files)).Count -gt 0) {
|
||||||
foreach ($file in $files) {
|
foreach ($file in $files) {
|
||||||
try {
|
try {
|
||||||
$stream = [System.IO.File]::Open($file.FullName, [System.IO.FileMode]::Open, [System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None);
|
$stream = [System.IO.File]::Open($file.FullName, [System.IO.FileMode]::Open, [System.IO.FileAccess]::ReadWrite, [System.IO.FileShare]::None);
|
||||||
|
|
||||||
if ($stream) {
|
if ($stream) {
|
||||||
$stream.Close();
|
$stream.Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
return $true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch {
|
|
||||||
return $true;
|
return $false;
|
||||||
}
|
} else {
|
||||||
|
return $true;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return $false;
|
$browser = [OpenQA.Selenium.Firefox.FirefoxDriver]::new($options);
|
||||||
} else {
|
$browser.Navigate().GoToUrl($URL);
|
||||||
return $true;
|
& $Action -Browser $browser;
|
||||||
|
|
||||||
|
while (& $downloadChecker) {
|
||||||
|
Write-Host "Waiting for the download to finish…";
|
||||||
|
Start-Sleep 1;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
$browser = [OpenQA.Selenium.Firefox.FirefoxDriver]::new($options);
|
$file = Get-ChildItem $dir;
|
||||||
$browser.Navigate().GoToUrl($URL);
|
$result = Move-Item $file $OutDir -PassThru;
|
||||||
& $Action -Browser $browser;
|
$browser.Quit();
|
||||||
|
Remove-Item -Recurse $dir;
|
||||||
while (& $downloadChecker) {
|
$result;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
<#
|
<#
|
||||||
|
|
Loading…
Reference in a new issue