We help IT Professionals succeed at work.
Get Started

System Object Powershell struggling to click button

165 Views
1 Endorsement
Last Modified: 2020-01-21
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()

Open in new window


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()

Open in new window


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
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE