Skip to content

Instantly share code, notes, and snippets.

@RahulARanger
Last active July 1, 2025 18:55
Show Gist options
  • Select an option

  • Save RahulARanger/05910c3d1baccad75c314e7fc6bfaf77 to your computer and use it in GitHub Desktop.

Select an option

Save RahulARanger/05910c3d1baccad75c314e7fc6bfaf77 to your computer and use it in GitHub Desktop.
Gets the Status of VISA from the VFS

You need Firefox installed; else, you can refer to selenium-ps1 docs: https://github.com/adamdriscoll/selenium-powershell Install-Module Selenium

This is .env file you can add it

LastName=XXXXXX
ID=XXXXXXX
HEADLESS=true
GETRESULTSELECTOR="#Index > div:nth-child(20) > b:nth-child(1)"
URL="https://www.vfsvisaonline.com/Global-Passporttracking/Track/Index?q=shSA0YnE4pLF9Xzwon/x/Ey/UM5rKPMuPWoM9so6dErw9MlQ/wjq9lJGkU959vsBmkhRMxhLmcmVTwlfacbFEp47383y+pPlAc0nVGEpKc0="

In order to add it in schedule, you can follow this

Create a VBScript file:

Set objShell = CreateObject("WScript.Shell")
objShell.Run "powershell.exe -ExecutionPolicy Bypass -File ""XXX\get-visa-status-from-vfs.ps1""", 0, False

Then run this script in CMD (admin mode)

SchTasks /Create /TN "Get Visa Status" /TR "wscript.exe \"XXX\get-visa-status.vbs\"" /SC ONLOGON /RL HIGHEST /F

now you will see ur status everyday after you login.


image image

FYI: https://stackoverflow.com/a/68426026/12318454 in case you get

Exception calling ".ctor" with "2" argument(s): "Expected browser binary location, but unable to find binary in default 
location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
(SessionNotCreated)"
At C:\Program Files\WindowsPowerShell\Modules\Selenium\3.0.1\Selenium.psm1:459 char:9
+         $Driver = [OpenQA.Selenium.Firefox.FirefoxDriver]::new($servi ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : InvalidOperationException
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment