Log into website using powershell

I want to log into a website using a username and password, so I copied the following code and executed. In result the webpage is opening but its not logging into the webpage and getting the following error.

Any suggestions?

$ie = New-Object -com InternetExplorer.Application 
$ie.visible=$true
$ie.navigate("url") 
while($ie.ReadyState -ne 4) {start-sleep -m 500} 
$ie.Document.getElementById("ctl00_username").value = "abcdef" 
$ie.Document.getElementById("ctl00_password").value = "123456" 
$ie.Document.getElementById("ctl00_login").click()
start-sleep 20 
$ie.Document.body | Out-File -FilePath C:\Users\averm\Documents\adi\test\web123.txt 

Open in new window


Exception from HRESULT: 0x80020101
At line:7 char:1
+ $ie.Document.getElementById("ctl00_usernamerequiredvalidator").value  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
 
Exception from HRESULT: 0x80020101
At line:8 char:1
+ $ie.Document.getElementById("ctl00_passwordrequiredvalidator").value  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException
 
Exception from HRESULT: 0x80020101
At line:9 char:1
+ $ie.Document.getElementById("ctl00_login").click()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [], COMException
    + FullyQualifiedErrorId : System.Runtime.InteropServices.COMException

Open in new window

aditya vermaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
Can you share the URL to the website, or a copy of the HTML that is presented in the browser?  My guess would be that the controls you are referencing may not exist or may be of a different type, etc.  But without knowing what the page HTML looks like it is hard to be specific.


»bp
0
Sajen JoseCommented:
I agree with Bill, also when the web page opens up, do you see the username field having the value that you provided in your script - for e.g. abcdef ?
0
aditya vermaAuthor Commented:
Here is my URL:   https://sfe-uat.epway.com

I'm giving exact values for user name Element ID = ctl00_username
for Password Element ID = ctl00_password
for login id = ctl00_login

username and password are not correct credentials. I just gave as example.
0
Introducing the "443 Security Simplified" Podcast

This new podcast puts you inside the minds of leading white-hat hackers and security researchers. Hosts Marc Laliberte and Corey Nachreiner turn complex security concepts into easily understood and actionable insights on the latest cyber security headlines and trends.

Bill PrewCommented:
Giv e this a try:

$ie = New-Object -com InternetExplorer.Application 
$ie.visible=$true
$ie.navigate("https://sfe-uat.epway.com") 
while($ie.Busy -or $ie.ReadyState -ne 4) {start-sleep -m 500} 
$ie.Document.IHTMLDocument3_getElementById("ctl00_username").value = "abcdef" 
$ie.Document.IHTMLDocument3_getElementById("ctl00_password").value = "123456" 
$ie.Document.IHTMLDocument3_getElementById("ctl00_login").click()
start-sleep 2
$ie.Document.body | Out-File -FilePath C:\Users\averm\Documents\adi\test\web123.txt

Open in new window


»bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aditya vermaAuthor Commented:
Code Worked for me. Thanks a lot.
0
Bill PrewCommented:
Great, glad that helped.


»bp
0
aditya vermaAuthor Commented:
Now actually I need some more help with this code. I'm logging into the page but i need to download a statement. The attached images shows you what to download.

Step1: In home page under "Reports" i need to select "Aging"
Step2: In "Aging" page i need to go to "Aging Group" and select "Direct Energy Aging" and select "Export". so that it will download my statement.

The following 4 images may help you to get some information. Please help me to find the solution.
1.png
2.png
3.png
4.png
0
Bill PrewCommented:
Since your original question was solved by this comment, you might want to mark that as a Solution to this question, and then open a new question for the additional help you need navigating the follow on pages.  Some new experts may find the new question better that way...


»bp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.