Avatar of PeggieGreg
PeggieGreg
 asked on

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
PowershellInternet Explorer (IE)

Avatar of undefined
Last Comment
PeggieGreg

8/22/2022 - Mon
PeggieGreg

ASKER
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
oBdA

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

Open in new window

PeggieGreg

ASKER
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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
oBdA

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
PeggieGreg

ASKER
very helpful and worked perfectly.

how did you know it was: Document.IHTMLDocument3_getElementByID ?