Need Help with Code for Auto Logon to a Website

by Shellshocked at 2013-03-15 11:12:08

Hello,

I’m new to Powershell and was wanting to get some help with a script. I was trying to create a script to auto logon to a website. Currently my script will open the web page but after that nothing happens. I was hoping some one could review my script and the source of the web page and help with where i’m going wrong. I will post the script and the source page below.



Script

$username = “name”
$password = “password”

$ie = New-Object -comobject InternetExplorer.Application
$ie.visible = $true
$ie.silent = $true
$ie.Navigate( “http://site”)
while($ie.ReadyState -ne 4){Start-Sleep -m 100}
$ie.Document.getElementById(“webUsername”).value = “$username”
$ie.Document.getElementById(“webPassword”).value = “$password”
$ie.Document.getElementById(“submit”).IHTMLElement_click()




Source


<script type=“text/javascript”>
var timerVal = 0;
var sessionLoggedIn = 0;

</script>

<body onLoad=“Docload()”>
<form method=“post” action="/userpost/name.set">
<div class=“boundingBox normalSpacing addTopMargin”>
<input type=“hidden” name="_fun_function" value=“HTTP_Authenticate_fn”>
<input type=“hidden” name=“NextPage” value="/properties/authentication/luidLogin.php">

<div class=“titleBar”>
<h3>Login</h3>
</div>
<div class=“boxBody”>
<h6>User ID</h6>
<div class=“component”>
<input type=“text” name=“webUsername” size=“32” maxlength=“32”>
</div>

<h6>Password</h6>
<div class=“component”>
<input type=“password” name=“webPassword” size=“32” maxlength=“63”>
</div><input type=“hidden” name=“frmaltDomain” value=“default”> </div>
</div>
<div class=“horizButtonBarBelowTableLeft”>
<button type=“submit”>Login</button>
</div>
<script type=“text/javascript”>
document.forms[0].webUsername.focus();</script></form>

</body>
</html>
by DonJ at 2013-03-16 09:08:11
You’re using GetElementByID but the submit button doesn’t have an ID. Its type attribute does not constitute an ID attribute. In fact, none of the input elements have an ID - a “name” is also not “id.”