Add script for automatically executing interactive downloads
This commit is contained in:
parent
5f81457d60
commit
09422bd435
1 changed files with 30 additions and 0 deletions
30
scripts/Windows/Scripts/BrowserAutomation.ps1
Normal file
30
scripts/Windows/Scripts/BrowserAutomation.ps1
Normal file
|
@ -0,0 +1,30 @@
|
|||
#!/bin/bash
|
||||
. "$PSScriptRoot/Context.ps1";
|
||||
|
||||
if (-not ("OpenQA.Selenium.Firefox.FirefoxDriver" -as [type])) {
|
||||
$zipFile = [System.IO.Compression.ZipFile]::OpenRead((Get-Package Selenium.WebDriver).Source);
|
||||
$stream = [System.IO.MemoryStream]::new();
|
||||
$reader = [System.IO.StreamReader]($zipFile.Entries[2]).Open();
|
||||
$reader.BaseStream.CopyTo($stream);
|
||||
[byte[]]$bytes = $stream.ToArray();
|
||||
$reader.Close();
|
||||
$zipFile.Dispose();
|
||||
[System.Reflection.Assembly]::Load($bytes);
|
||||
}
|
||||
|
||||
function Start-AutomatedDownload() {
|
||||
param(
|
||||
[Context] $context,
|
||||
[string] $url,
|
||||
[string] $buttonSelector
|
||||
)
|
||||
|
||||
$tempDir = $context.GetTempDirectory();
|
||||
$options = [OpenQA.Selenium.Firefox.FirefoxOptions]::new();
|
||||
$options.SetPreference("browser.download.folderList", 2);
|
||||
$options.SetPreference("browser.download.dir", $tempDir);
|
||||
# $options.AddArgument("--headless");
|
||||
$browser = [OpenQA.Selenium.Firefox.FirefoxDriver]::new($options);
|
||||
$browser.Navigate().GoToUrl($url);
|
||||
$browser.FindElement($buttonSelector).Click();
|
||||
}
|
Loading…
Reference in a new issue