1

I need to log on to a web page with credentials from the get-credential window. But I am getting error- Property 'Value' cannot be found on this object; make sure it exists and is settable.I have provided my powershell source code here..

$url = "ameriprisestage.service-now.com/"
$cred = Get-Credential 
$username = $cred.username
$username = $username.Replace("\", "")
$password = $cred.GetNetworkCredential().password
$ie = New-Object -com internetexplorer.application; 
$ie.visible = $true; 
$ie.navigate($url); 
while ($ie.ReadyState -ne 4 -or $ie.Busy)
{
    start-sleep -milliseconds 100
}
 #$uname=$ie.Document.getElementsByTagName("input") 
#$unameBox=$uname | where { $_.name -eq "user_name" }
$unameBox=$ie.Document.getElementById("user_name")
$unameBox.value = $username
$pass=$ie.Document.getElementsByTagName("input") | ? { $_.id -eq "user_password" }
$pass.value = $password
$pass.select
$buttn=$ie.Document.getElementsByTagName("button") | ? { $_.id -eq "sysverb_login" }
$buttn.click()
while($ie.busy) {
Start-sleep 1;
}
5
  • Perhaps the web page is not fully rendered by the time you call getElementsByTagName. Just because IE reports that it is no longer busy does not mean any/all page load scripts have completed. Might be worth coding a loop to wait until this step is successful. Commented Aug 6, 2014 at 6:16
  • i tried with `getelementById' too.Not working Commented Aug 6, 2014 at 6:39
  • My point is that the element may not be there to find. Try inserting a start-sleep -seconds 60 before querying the DOM. This should give the page time to render. If it still fails then either you are looking for elements that don't exist, or using the wrong syntax. Commented Aug 6, 2014 at 6:54
  • See my answer to stackoverflow.com/questions/22510779/… Commented Aug 6, 2014 at 6:55
  • It is not working.I tried Commented Aug 6, 2014 at 8:09

1 Answer 1

1

There are multiple windows in the web page. Try to redirect it to the relevant window.

cd HKCU:\"Software\Microsoft\Windows\CurrentVersion\Internet Settings"
set-itemproperty . ProxyEnable 1
$url = "https://ameriprisestage.service-now.com/"
#function call 

#$cred = Get-Credential 
$username = "asset_tester02"
$username = "asset_tester02"
$password = "tester02"
$ie = New-Object -com internetexplorer.application; 
$ie.visible = $true; 
$ie.navigate($url); 
while ($ie.Busy -eq $true) 
{ 
    Start-Sleep 1; 
} 

$usr=$ie.document.getElementbyID("gsft_main").contentWindow.document.getElementbyID("user_name").value=$username
$pass=$ie.document.getElementbyID("gsft_main").contentWindow.document.getElementById("user_password").value= $password
$buttn=$ie.document.getElementbyID("gsft_main").contentWindow.document.getElementById("sysverb_login").click()
Sign up to request clarification or add additional context in comments.

Comments

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.