Link to home
Start Free TrialLog in
Avatar of aditya verma
aditya verma

asked on

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

Avatar of Bill Prew
Bill Prew

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
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 ?
Avatar of aditya verma

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Code Worked for me. Thanks a lot.
Great, glad that helped.


»bp
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
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