Install Selenium: function Install-PSArchive {
param() $null = Install-PackageProvider -Name PowerShellGet -Force -Scope
CurrentUser Install-Module -Name 'Microsoft.PowerShell.Archive' -Force
-Repository PSGallery -Scope CurrentUser -WarningAction SilentlyContinue }
function Install-Selenium { param($ChromeSeleniumVersion = '2.45')
Invoke-WebRequest -Uri
'https://www.nuget.org/api/v2/package/Selenium.WebDriver/' -UseBasicParsing
-OutFile './selenium.webDriver.nupkg.zip' Expand-Archive -Path
./selenium.webDriver.nupkg.zip -Force $null = New-Item -Name
'./lib/selenium.webDriver' -ItemType Directory -Force Copy-Item -Path
./selenium.webDriver.nupkg/lib/netstandard2.0/WebDriver.dll -Destination
./lib/selenium.webDriver -Force Copy-Item -Path
./selenium.webDriver.nupkg/lib/netstandard2.0/WebDriver.xml -Destination
./lib/selenium.webDriver -Force Remove-Item -Recurse -Force -Path
'./selenium.webDriver.nupkg' Remove-Item -Recurse -Force -Path
'./selenium.webDriver.nupkg.zip' $ChromeSeleniumURLLinux =
'https://chromedriver.storage.googleapis.com/{0}/chromedriver_linux64.zip' -f
$ChromeSeleniumVersion $ChromeSeleniumURLMacOS =
'https://chromedriver.storage.googleapis.com/{0}/chromedriver_mac64.zip' -f
$ChromeSeleniumVersion $ChromeSeleniumURLWindows =
'https://chromedriver.storage.googleapis.com/{0}/chromedriver_win32.zip' -f
$ChromeSeleniumVersion If ($IsWindows) { Invoke-WebRequest -Uri
$ChromeSeleniumURLWindows -OutFile 'chromedriver.zip' } elseif ($IsLinux) {
Invoke-WebRequest -Uri $ChromeSeleniumURLLinux -OutFile 'chromedriver.zip' }
elseif ($IsMacOS) { Invoke-WebRequest -Uri $ChromeSeleniumURLMacOS -OutFile
'chromedriver.zip' } else { Write-Error -Message 'Platform not supported.' }
$null = New-Item -Name './bin/selenium.chromedriver' -Force -ItemType
Directory Expand-Archive -Path 'chromedriver.zip' -Force -DestinationPath
./bin/selenium.chromedriver Remove-Item -Recurse -Force -Path
'./chromedriver.zip' If ($IsLinux -or $IsMacOS) { chmod a+x
./bin/selenium.chromedriver/chromedriver } } function Install-HtmlAgilityPack
{ param() Invoke-WebRequest -Uri
'https://www.nuget.org/api/v2/package/HtmlAgilityPack/' -OutFile
./HtmlAgilityPack.zip Expand-Archive -Path './HtmlAgilityPack.zip' -Force
$null = New-Item -Name './lib/HtmlAgilityPack' -ItemType Directory -Force
Copy-Item -Path ./HtmlAgilityPack/lib/netstandard2.0/HtmlAgilityPack.dll
-Destination ./lib/HtmlAgilityPack -Force Copy-Item -Path
./HtmlAgilityPack/lib/netstandard2.0/HtmlAgilityPack.xml -Destination
./lib/HtmlAgilityPack -Force Remove-Item -Force -Recurse -Path
'./HtmlAgilityPack' Remove-Item -Force -Recurse -Path './HtmlAgilityPack.zip'
} Install-PSArchive Import-Module -Name 'Microsoft.PowerShell.Archive'
Install-Selenium Import-Module './lib/selenium.webDriver/WebDrive' ## If you
need to parse some html inside of your scripts and want to have cross platform
functionality (or if internet explorer is not enabled), you also need to
install HtmlAgilityPack, as powershell on windows relies upon it for parsing
html into objects. Install-HtmlAgilityPack Import-Module
'./lib/HtmlAgilityPack/HtmlAgilityPack.dll'
administration, development, powershell, security, webserver,
Install Selenium
Share this