Leo Torres
asked on
Powershell login to website
I dont think I have the correct tags here
Error I get
Here is the HTML tags I am looking at to try and log in. Not sure what I am doing wrong
CLS
$url = "www.SomeSite.com"
$ie = New-Object -comobject InternetExplorer.Application
$ie.visible = $true
$ie.silent = $true
$ie.Navigate( $url )
while( $ie.busy){Start-Sleep 1}
#$secLink = $ie.Document.getElementsByTagName('A') | Where-Object {$_.innerText -eq 'Continue to this website (not recommended).'}
#$secLink.click()
$ie.Document.getElementsByType("input") | where { $.Name -eq "loginInput" }.value = "UserName"
$ie.Document.getElementsByName("input") | where { $.Name -eq "passwordField" }.value = "password"
$loginBtn = $ie.Document.getElementsById('input') | Where-Object {$_.Type -eq 'button' -and $_.Value -eq 'Login'}
$loginBtn.click()
Error I get
Method invocation failed because [mshtml.HTMLDocumentClass] does not contain a method named 'getElementsByType'.
At line:10 char:1
+ $ie.Document.getElementsByType("input") | where { $.Name -eq "loginInput" }.valu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Where-Object : Cannot bind argument to parameter 'FilterScript' because it is null.
At line:11 char:49
+ $ie.Document.getElementsByName("input") | where { $.Name -eq "passwordField" }.v ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Where-Object], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.WhereObjectCommand
Method invocation failed because [mshtml.HTMLDocumentClass] does not contain a method named 'getElementsById'.
At line:12 char:1
+ $loginBtn = $ie.Document.getElementsById('input') | Where-Object {$_.Type -eq 'b ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
You cannot call a method on a null-valued expression.
At line:13 char:1
+ $loginBtn.click()
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
Here is the HTML tags I am looking at to try and log in. Not sure what I am doing wrong
ASKER
Code produced this error.
The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At line:12 char:1
+ ($ie.Document.getElementsByName("input") | where { $.Name -eq "loginInput" }).va ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At line:13 char:1
+ ($ie.Document.getElementsByName("input") | where { $.Name -eq "passwordField" }) ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Method invocation failed because [mshtml.HTMLDocumentClass] does not contain a method named 'getElementsById'.
At line:14 char:1
+ $loginBtn = $ie.Document.getElementsById('input') | Where-Object {$_.Type -eq 'b ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
You cannot call a method on a null-valued expression.
At line:15 char:1
+ $loginBtn.click()
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
ASKER
There is no value inside the node. I believe that is what is causing error. loginInput is the text field that holds User name text but there is no Value tag. Could it be we need to use id="loginfield" ?
I'm using this sequence to log in:
$ie.Document.getElementsByTagName("input") | ? { $_.Id -eq 'username' } | % { $_.value = "MyUsername" }
$ie.Document.getElementsByTagName("input") | ? { $_.Id -eq 'password' } | % { $_.value = "MyPassword" }
$ie.Document.getElementsByTagName("input") | ? { $_.Type -eq 'submit' } | % { $_.Click() }
and it works great. But that depends on the site we query.
ASKER
ASKER
OK was able to get pass that first button
with this code
Currently I have this command and it just sits on page
I think its because there are other buttons on page. Could it be the other buttons are ALL buttons
with this code
$ie.Document.getElementsByTagName("input") | ? { $_.Id -eq 'loginField' } | % { $_.value = "User" }
$ie.Document.getElementsByTagName("input") | ? { $_.Id -eq 'passwordField' } | % { $_.value = "pass" }
$ie.Document.getElementsByTagName("button") | ? { $_.Type -eq 'button' } | % { $_.Click() }
But I need to click this button and its a bit different. I need to press Go button NOT Cancel button.Currently I have this command and it just sits on page
$ie.Document.getElementsByTagName("button") | ? { $_.Type -eq 'button' -and $_.name -eq "Go" } | % { $_.Click() }
I think its because there are other buttons on page. Could it be the other buttons are ALL buttons
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The Select only returned Type button the name and ID was blank
Think I got passed this question.
can you help me in the next phase
https://www.experts-exchange.com/questions/28494068/Powershell-get-href-from-page-and-assign-to-variable.html
Thank you!
Think I got passed this question.
can you help me in the next phase
https://www.experts-exchange.com/questions/28494068/Powershell-get-href-from-page-and-assign-to-variable.html
Thank you!
1. You've used getElementsByType instead of getElementsByName once
2. You can't request a .value from a scriptblock - you intended to apply that to the result of where:
Open in new window
Maybe you have to use GetElementsById instead of GetElementsByName.