|
Add-Type -AssemblyName PresentationFramework |
|
Import-Module Selenium |
|
|
|
$scriptpath = $MyInvocation.MyCommand.Path | split-path |
|
$env_file = Join-Path $scriptpath '.env' |
|
|
|
Get-Content $env_file | ForEach-Object { |
|
$line = $_.Trim() |
|
if ($line -like '#*' -or -not ($line -match '^([A-Za-z_]+)=(.*)$')) { |
|
return |
|
} |
|
|
|
$name, $value = $line -split '=', 2 |
|
Set-Content "env:\$name" $value |
|
} |
|
|
|
$url = $env:URL -replace '"', '' |
|
$ResultSelector = $env:GETRESULTSELECTOR -replace '"', '' |
|
|
|
$Driver = Start-SeFirefox -Headless |
|
Enter-SeUrl -Driver $Driver -Url $url |
|
|
|
$Ref = Find-SeElement -Driver $Driver -Id "AppRefNo" -Wait -Timeout 10 |
|
Send-SeKeys -Element $Ref -Keys $env:ID |
|
|
|
$Element = Find-SeElement -Driver $Driver -Name "LastName" -Wait -Timeout 10 |
|
Send-SeKeys -Element $Element -Keys $env:LastName |
|
|
|
$base64Image = $Driver.ExecuteScript(@" |
|
var img = document.getElementById('CaptchaImage'); |
|
var canvas = document.createElement('canvas'); |
|
canvas.width = img.width; |
|
canvas.height = img.height; |
|
var ctx = canvas.getContext('2d'); |
|
ctx.drawImage(img, 0, 0); |
|
return canvas.toDataURL('image/png').split(',')[1]; |
|
"@) |
|
|
|
$bytes = [Convert]::FromBase64String($base64Image) |
|
$ms = New-Object System.IO.MemoryStream($bytes, 0, $bytes.Length) |
|
$bitmap = New-Object System.Windows.Media.Imaging.BitmapImage |
|
$bitmap.BeginInit() |
|
$bitmap.StreamSource = $ms |
|
$bitmap.EndInit() |
|
|
|
$window = New-Object Windows.Window |
|
$window.Title = "VISA Status" |
|
$window.Width = 350 |
|
$window.Height = 250 |
|
$window.ResizeMode = "NoResize" |
|
$window.WindowStartupLocation = "CenterScreen" |
|
$window.Topmost = $true |
|
|
|
$grid = New-Object Windows.Controls.Grid |
|
$window.Content = $grid |
|
$formGrid = New-Object Windows.Controls.Grid |
|
|
|
$grid.RowDefinitions.Add((New-Object Windows.Controls.RowDefinition)) |
|
$grid.RowDefinitions.Add((New-Object Windows.Controls.RowDefinition)) |
|
|
|
$formGrid.ColumnDefinitions.Add((New-Object Windows.Controls.ColumnDefinition)) |
|
$formGrid.ColumnDefinitions.Add((New-Object Windows.Controls.ColumnDefinition)) |
|
|
|
$image = New-Object Windows.Controls.Image |
|
$image.Source = $bitmap |
|
$image.Height = 150 |
|
$image.HorizontalAlignment = "Center" |
|
$image.SetValue([Windows.Controls.Grid]::RowProperty, 0) |
|
$grid.Children.Add($image) |
|
|
|
$formGrid.SetValue([Windows.Controls.Grid]::RowProperty, 1) |
|
$grid.Children.Add($formGrid) |
|
|
|
$textBox = New-Object Windows.Controls.TextBox |
|
$textBox.Width = 120 |
|
$textBox.Height = 25 |
|
$textBox.HorizontalAlignment = "Center" |
|
$textBox.VerticalAlignment = "Center" |
|
$textBox.SetValue([Windows.Controls.Grid]::ColumnProperty, 0) |
|
$formGrid.Children.Add($textBox) |
|
|
|
$button = New-Object Windows.Controls.Button |
|
$button.Content = "Go" |
|
$button.Width = 60 |
|
$button.Height = 25 |
|
$button.HorizontalAlignment = "Center" |
|
$button.SetValue([Windows.Controls.Grid]::ColumnProperty, 1) |
|
$formGrid.Children.Add($button) |
|
$enteredText = '' |
|
|
|
$button.Add_Click({ |
|
$button.IsEnabled = $false |
|
$script:enteredText = $textBox.Text |
|
$window.close() |
|
}) |
|
|
|
|
|
$window.ShowDialog() | Out-Null |
|
|
|
$CaptchaInput = Find-SeElement -Driver $Driver -Id "CaptchaInputText" |
|
Send-SeKeys -Element $CaptchaInput -Keys $enteredText |
|
|
|
$submitButton = Find-SeElement -Driver $Driver -Id "submitButton" |
|
Invoke-SeClick -Element $submitButton |
|
|
|
for ($check = 0; $check -le 6; $check++) { |
|
Start-Sleep -Seconds 2 |
|
|
|
$resultText = $Driver.ExecuteScript("return document.querySelector(arguments[0])?.textContent;", $ResultSelector) |
|
if ($resultText -ne '') { |
|
[System.Windows.MessageBox]::Show("Result: $resultText", "Result") |
|
break |
|
} |
|
} |
|
|
|
$Driver.Quit() |