I'm trying to have a script where when my Internet disconnects, it automatically reconnects and logs into the Wifi. However, there is an error where I cannot make the script login.
while (Test-Connection 8.8.8.8 -Quiet) {
}
netsh wlan connect wifi-name
$ie = New-Object -Com InternetExplorer.Application
$ie.Visible = $false
$ie.Navigate("http://address/loginpage.php")
$link = $ie.Document.GetElementById("btnLogin")
$link.Click()
$ie.Quit()
It returns with this error:
You cannot call a method on a null-valued expression.
At line:12 char:1
+ $link = $ie.Document.GetElementById("btnLogin")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
At line:13 char:1
+ $link.Click()
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
I have made sure the ID is correct as well:

do {Start-Sleep -Milliseconds 100} until ($ie.ReadyState -eq 4 -and -not $ie.Busy)- Ansgar Wiechers