1

i am adding user id and password to website and trying to login to site. in below code i am not able to click on the Login button i tried click submit but not able to click. can any one please help me

$username = "abcd" 
$password = "abc" 
$ie = New-Object -com InternetExplorer.Application 
$ie.visible=$true
$ie.navigate("https://www.google.com/") 
while($ie.ReadyState -ne 4) {start-sleep -m 100} 
$ie.document.getElementById("loginId").value= "$username" 
$ie.document.getElementById("password").value = "$password" 
$fs = $ie.document.getElementById("loginButton")
$fs.click()

1 Answer 1

1

Instead of native getElementById method, use IHTMLDocument3_getElementById:

$username="myname"
$password="mypass"
$url = "https://www.google.com/"
$ie = New-Object -com InternetExplorer.Application
$ie.visible = $true
$ie.navigate($url)
while($ie.Busy) { Start-Sleep -Milliseconds 100 }
$ie.document.IHTMLDocument3_getElementById("loginId").value = $username
$ie.document.IHTMLDocument3_getElementById("password").value = $password
$ie.document.IHTMLDocument3_getElementById("loginButton").click()

It will show an alert stating "Login Name and Password combination is incorrect.".

It's working on my machine having IE11 and WIN10. There are 3 important changes in above code:

  • Using http rather than https because of IE problem with certificate of that site at the time which I tried the site.
  • Checking Busy property of IE to check if IE is busy, then wait for it.
  • Using IHTMLDocument3_getElementById instead of getElementById.
Sign up to request clarification or add additional context in comments.

18 Comments

it is giving error Exception from HRESULT: 0x800A01B6 At E:\electricbilllogin.ps1:11 char:1 + $ie.document.IHTMLDocument3_getElementById("loginButton").click() + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (:) [], NotSupportedException + FullyQualifiedErrorId : System.NotSupportedException
On my machine, it shows an alert stating "Login Name and Password combination is incorrect." And the key point for me is using IHTMLDocument3_getElementById instead of getElementById. Are you sure you copied and run exactly above code which I shared?
yes exact the same code. any pointer why it is giving error then
If I use getElementById, I receive the same error, but using IHTMLDocument3_getElementById everything works fine.
If you pay attention, I'm using http url rather than https because of IE problem with certificate of that site. So please make sure you copy the exact code from my answer and paste in ISE window and run it.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.