We help IT Professionals succeed at work.

System Object Powershell struggling to click button

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

PeggieGregInfrastructure Analyst

Author

Commented:
I have tried the following as well:

 
"Starting Internet Explorer in Background"
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$true
$uri = 'https://172.16.4.25/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()
#$loginbutton=($ie.Document.getElementsByclassName("c_login") |select -first 1).click()
#$loginclick=($ie.document.getElementsByName("f_login") |select -first 1).click()
$Loginbutton=($ie.Document.getElementsByclassName("big button") | where-object {$_.class -eq "Login"})[0]
$Loginbutton.click()

Open in new window




see the elements below.
button-element.PNG
Most Valuable Expert 2019
Most Valuable Expert 2018

Commented:
Obviously can't test it, but try
$Loginbutton = $ie.Document.getElementByID("submit_button")

Open in new window

PeggieGregInfrastructure Analyst

Author

Commented:
Exception from HRESULT: 0x800A01B6
At line:1 char:1
+ $Loginbutton = $ie.Document.getElementByID("submit_button")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], NotSupportedException
    + FullyQualifiedErrorId : System.NotSupportedException
 
this is the error I get. it is annoying.

if this helps at all full screen shot attached of elements. submit button looked good...

any other ideas?
Submit-Button.PNG
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
Then try it like this:
$Loginbutton = $ie.Document.IHTMLDocument3_getElementByID("submit_button")

Open in new window

PeggieGregInfrastructure Analyst

Author

Commented:
very helpful and worked perfectly.

how did you know it was: Document.IHTMLDocument3_getElementByID ?