troubleshooting Question

System Object Powershell struggling to click button

Avatar of PeggieGreg
PeggieGreg asked on
PowershellInternet Explorer (IE)
5 Comments1 Solution181 ViewsLast Modified:
Hello - I have the below script working OK. it creates an object and actions some things for IE.

all works in this script

 
"Starting Internet Explorer in Background"
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$true
$uri = 'https://MYWEBSITEIP/ossim/session/login.php#analysis/alarms/alarms'
#$ie.FullScreen = $true
$ie.TheaterMode = $true
$ie.navigate("$uri")
"Bypassing SSL Certificate Error Page";
start-sleep -s 5;
$sslbypass=$ie.Document.getElementsByTagName("a") | where-object {$_.id -eq "overridelink"}
$sslbypass.click()

but as soon as I try to click the logon button that's where my problems start... I have tried multiple ways to click it and it comes up with the error below the code. I know I only need to click login once but I tried C_login and F_login as these were the elements I could see on the webpage. tried other variants. but my error makes me thing its more than just the name wrong.

 
"Starting Internet Explorer in Background"
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$true
$uri = 'https://MYWEBSITEIP/ossim/session/login.php#analysis/alarms/alarms'
#$ie.FullScreen = $true
$ie.TheaterMode = $true
$ie.navigate("$uri")
"Bypassing SSL Certificate Error Page";
start-sleep -s 5;
$sslbypass=$ie.Document.getElementsByTagName("a") | where-object {$_.id -eq "overridelink"}
$sslbypass.click()
$loginclick=($ie.document.getElementsByName("c_login") |select -first 1).click()
$loginclick=($ie.document.getElementsByName("f_login") |select -first 1).click()

You cannot call a method on a null-valued expression.
At E:\KEEP\~Scripts\Get Internet Explorer and sign in.ps1:13 char:1
+ $loginclick=($ie.document.getElementsByName("c_login") |select -first ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
You cannot call a method on a null-valued expression.
At E:\KEEP\~Scripts\Get Internet Explorer and sign in.ps1:14 char:1
+ $loginclick=($ie.document.getElementsByName("f_login") |select -first ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros