Powershell login to website

What I find different about this page is that the html does not have a  value="" field to store user name and password for login so how can it be done.

cls
#if (!(Get-Variable ie -Scope global -ea SilentlyContinue)) { $global:ie = New-Object -comobject InternetExplorer.Application }
$ie = New-Object -comobject InternetExplorer.Application
$ie.visible = $true
$ie.silent  = $true



$wc = New-Object System.Net.WebClient
$login = "User"
$password = "password#"

$url = "https://ultidev/secure/Dashboard.jspa"

[string] $content = $wc.DownloadString($URL)

$ie.Navigate2($url)
  while ($ie.busy)                               { Start-Sleep -m 100 }
  while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }

Start-Sleep -s 5

$ie.Document.getElementsByTagName("input")  | ? { $_.Id   -eq 'login-form-username' } | % { $_.value = $login    }
$ie.Document.getElementsByTagName("input")  | ? { $_.Id   -eq 'login-form-password' } | % { $_.value = $password }
$ie.Document.getElementsByTagName("button") | ? { $_.Type -eq 'login'        } | % { $_.Click() }

Open in new window




<div class="view g-login"><div id="content"><form name="loginform" class="aui gdt" id="loginform" action="#" method="post"><div class="field-group"><label id="usernamelabel" accesskey="u" for="login-form-username"><u>U</u>sername</label><input name="os_username" class="text medium-field" id="login-form-username" type="text"></div><div class="field-group password"><label id="passwordlabel" accesskey="p" for="login-form-password"><u>P</u>assword</label><input name="os_password" class="text medium-field" id="login-form-password" type="password"></div><fieldset class="group"><div class="checkbox" id="rememberme"><input name="os_cookie" class="checkbox" id="login-form-remember-me" type="checkbox" value="true"><label id="remembermelabel" accesskey="r" for="login-form-remember-me"><u>R</u>emember my login on this computer</label></div></fieldset><div class="field-group hidden" id="captcha"><label id="captchalabel" accesskey="c" for="login-form-captcha">Please enter the word as shown below</label><input name="os_captcha" class="text medium-field captcha-response" id="login-form-captcha" type="text"><div class="captcha-container"><img width="200" height="100" class="captcha-image" id="captchaimg" alt="" src=""><a tabindex="-1" title="Refresh the image" class="captcha-trigger" id="os-captcha-icon" href="#login-form-os-captcha"><span class="aui-icon captcha-reload icon-reload">Refresh the image</span></a></div></div><div class="field-group" id="publicmodeooff"><div id="publicmodeoffmsg">Not a member? To request an account, please contact your <a id="contact-admin" href="https://ultidev/secure/ContactAdministrators!default.jspa" target="_parent">JIRA administrators</a>.</div></div><div class="buttons-container"><div class="buttons"><input name="login" class="button" id="login" type="submit" value="Log In"><a class="button aui-button-cancel cancel" id="forgotpassword" href="https://ultidev/secure/ForgotLoginDetails.jspa" target="_parent">Can't access your account?</a></div></div></form></div></div>

Open in new window

LVL 8
Leo TorresSQL DeveloperAsked:
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.

rwniceingCommented:
You  can  try to add this

$ie.Document.getElementById("login-form-username").value= "$login"
$ie.Document.getElementById("login-form-password").value = "$password"
0
Leo TorresSQL DeveloperAuthor Commented:
Add or Replace what I have with what you suggested?
0
rwniceingCommented:
you can set the default value for input tage 's  username and password  inside  the form so that you can submit the form with the username and password you set at

$login = "User"
$password = "password#"

<form name="loginform" class="aui gdt" id="loginform" action="#" method="post">
<div class="field-group"><label id="usernamelabel" accesskey="u" for="login-form-username"><u>U</u>sername</label>
<input name="os_username" class="text medium-field" id="login-form-username" type="text"></div>
<div class="field-group password"><label id="passwordlabel" accesskey="p" for="login-form-password"><u>P</u>assword</label>
<input name="os_password" class="text medium-field" id="login-form-password" type="password"></div>
.....................

</form>

Open in new window

0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

rwniceingCommented:
it seems your post code is already done your need.

Actually did you try your code, working or not ? OR could you write more about your question
0
Leo TorresSQL DeveloperAuthor Commented:
Code does not work now it produces error.


The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At line:25 char:1
+ $ie.Document.getElementById("login-form-username").value= "$login"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + 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:26 char:1
+ $ie.Document.getElementById("login-form-password").value = "$password"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

Open in new window

0
rwniceingCommented:
Could you post the whole code ? where you put those two lines in  the code ?


This link is good reference to your question at EE link
http://www.experts-exchange.com/Programming/Languages/Scripting/Powershell/Q_28379350.html
0
Leo TorresSQL DeveloperAuthor Commented:
OK here is the code but I dont see the Username tag any where I wonder if its encrypted or something.

Here is the code thru DOM Explorer

COde
I cant see this in HTML Wonder if this is a deal breaker.
Sample.html
0
rwniceingCommented:
$login = "User"
$password = "password#"

$ie.Document.getElementById("login-form-username").value= "$login"
$ie.Document.getElementById("login-form-password").value = "$password"

the userlogin name is at input tag with id , login-form-username , so you
just put your username at  $login

where those two code you put ,please read the reference link
0
Leo TorresSQL DeveloperAuthor Commented:
Produced Error

The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At line:17 char:1
+ $ie.Document.getElementById("login-form-username").value= "$login"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + 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:18 char:1
+ $ie.Document.getElementById("login-form-password").value = "$password"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

Open in new window


Actual code
$login = "ID"
$password = "passwd"

$ie = New-Object -comobject InternetExplorer.Application
$ie.visible = $true
$ie.silent  = $true

$ie.Navigate2($url)
  while ($ie.busy)                               { Start-Sleep -m 100 }
  while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }


$ie.Document.getElementById("login-form-username").value= "$login"
$ie.Document.getElementById("login-form-password").value = "$password"

Open in new window

0
rwniceingCommented:
What is url full path ?
Could you try to Navigate instead of  Navigate2

On VBA, value should be Value , but  probably on here , it is okay
for lower case of 'v" ?
0
rwniceingCommented:
while($ie.ReadyState -ne 4) is not  while ($ie.Document.ReadyState -ne "Complete") that   will cause issue since the document is not ready so there is no object with value Please check it out
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
rwniceing,

.value or .Value does not matter. Nor does .Navigate or .Navigate2. The latter is able to resolve more than an URL, e.g. a file with registered type, that is all.

In regard of the ready state, since IE isn't busy anymore, the document is available - it might be not ready yet (but should). That will not cause an issue.


Leo,

You should first see if typing
$ie.Document.getElementById("login-form-username")
$ie.Document.getElementById("content").getElementById("login-form-username")

Open in new window

shows any object.
0
Leo TorresSQL DeveloperAuthor Commented:
Not at work now will try to test this tomorrow
0
Leo TorresSQL DeveloperAuthor Commented:
Guys sorry for the delay. I have been sick and out the past week. I will be back on the next for days

Code opens page put does not enter data into fields

cls
#if (!(Get-Variable ie -Scope global -ea SilentlyContinue)) { $global:ie = New-Object -comobject InternetExplorer.Application }
$ie = New-Object -comobject InternetExplorer.Application
$ie.visible = $true
$ie.silent  = $true

$wc = New-Object System.Net.WebClient
$login = "User"
$password = "pass"

$url = "https://ultidev/secure/Dashboard.jspa"

[string] $content = $wc.DownloadString($URL)

$ie.Navigate2($url)
  while ($ie.busy)                               { Start-Sleep -m 100 }
  while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }

Start-Sleep -s 5

$ie.Document.getElementById("login-form-username")
$ie.Document.getElementById("content").getElementById("login-form-username")

#$ie.Document.getElementById("content").getElementById("login-form-username") | ? { $_.Id   -eq 'login-form-username' } | % { $_.value = $login }
#$ie.Document.getElementById("login-form-username").value= "$login"
#$ie.Document.getElementById("login-form-password").value = "$password" 
#$ie.Document.getElementsByTagName("input")  | ? { $_.Id   -eq 'login-form-username' } | % { $_.value = $login    }
#$ie.Document.getElementsByTagName("input")  | ? { $_.Id   -eq 'login-form-password' } | % { $_.value = $password }
#$ie.Document.getElementsByTagName("button") | ? { $_.Type -eq 'login'        } | % { $_.Click() }

Write-Host $content

Open in new window

0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Lines 21 and 22 should have some output - do they? You need not to execute the lines following those for now.
0
Leo TorresSQL DeveloperAuthor Commented:
Here is the out put

Image
0
Leo TorresSQL DeveloperAuthor Commented:
The web page comes up but the User name is not filled in
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Ok, try if
 ($ie.Document.getElementById("login-form-username") | select -first 1).value = 'x'
sets something in the username field. We do not have to do that with the HTML fragment you posted in the question, but maybe you have to on your real page.

If that works, use (I've removed some irrelevant code you might have to readd for your purpose):
cls
#if (!(Get-Variable ie -Scope global -ea SilentlyContinue)) { $global:ie = New-Object -comobject InternetExplorer.Application }
$ie = New-Object -comobject InternetExplorer.Application
$ie.visible = $true
$ie.silent  = $true

$login = "User"
$password = "pass"

$url = "https://ultidev/secure/Dashboard.jspa"

$ie.Navigate2($url)
while ($ie.busy)                               { Start-Sleep -m 100 }
while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }

Start-Sleep -s 5

($ie.Document.getElementById("login-form-username") | select -first 1).value = $login
($ie.Document.getElementById("login-form-password") | select -first 1).value = $password
$ie.Document.getElementsByTagName("button") | ? { $_.Type -eq 'login'        } | % { $_.Click() }

Open in new window

0
Leo TorresSQL DeveloperAuthor Commented:
Code produced this error.

The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At line:19 char:1
+ ($ie.Document.getElementById("login-form-username") | select -first 1).value = $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + 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:20 char:1
+ ($ie.Document.getElementById("login-form-password") | select -first 1).value = $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

Open in new window


I have also attached page source here.
jiraSite.txt
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
No, that is not the correct site code. It is the dashboard, and you need to click the "Log In" link to go to a login page.
0
Leo TorresSQL DeveloperAuthor Commented:
This is the site code here it is again

Here is what the page looks like
page
Any reason why you think this is not the code?
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
This is what I see:jiraSite.png
0
Leo TorresSQL DeveloperAuthor Commented:
Yes your right. I get the same thing.

I went to link then had it show source. copied pasted it did it twice to make sure. same thing.

if I do a get-content I get the same file .

How ever if I open the page and hit F12 and copy  from the DOM Explorer I do see the login fields.

I have attached new html file here from DOM Explorer. Hope this works?
jiraSite-DOMExplorer.txt
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Nope, seems to be active code instead of static fields. And that is probably the reason the PS code does not work.
0
Leo TorresSQL DeveloperAuthor Commented:
So your saying it cant be done?
0
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
No, not saying that, but probably you are the only one able to check and solve. You are seeing different stuff than we do.

You'll have to dump part of the code PS sees at that moment you see the login, and then try to find the object with getElementByID or getElementsByXXX (tagname, name, type, ...). Play with it, don't be focussed on the static code for now. As soon as you are able to fill in login data with an assignment, you can put that into the code. That is the way I work with such stuff.
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
Leo TorresSQL DeveloperAuthor Commented:
Sorry about the delay gave you guys. I really want to do this I will repost. Just have to many things going on.
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.