I need to log into a web page to run several reports and I am trying to create a powershell script to run them unattended. The standard info I find on the web is not working for me. Here is a snippet of the code where I need to input my user and password. I think the issue is I need to refer to both usernamearea and usernameTxt but I have no idea how to do that and couldn't figure it out using google.
Login snippet:
<form method="post" action="Login.aspx?appId=8" id="loginForm">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTMxNDc3MDQ4M2RkILEi0T+EQ2bUkVjyWhK40U41H6ZFy9T/RL1b+qGCu5Q=" />
</div>
<div class="aspNetHidden">
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWBAKSit/iCwL58NOdCgLH6tDICwKeuv4ZG00aF05Js4SN/jPm9k3CXdUB9Gru8bLgyHyQ6q/Vd4Y=" />
</div>
<div id="usernameArea">
<h4><span class="label label-default">
<span class="eng">Username</span>
<span class="fre">Nom d'utilisateur</span>
</span></h4>
<input name="ctl00$ContentPlaceHolder1$usernameTxt" type="text" id="usernameTxt" class="form-control" />
</div>
<div id="passwordArea">
<h4><span class="label label-default">
<span class="eng">Password</span>
<span class="fre">Mot de passe</span>
</span></h4>
<input name="ctl00$ContentPlaceHolder1$passwordTxt" type="password" id="passwordTxt" class="form-control" />
</div>
<input type="submit" name="ctl00$ContentPlaceHolder1$tryLoginBtn" value="Login" id="tryLoginBtn" class="btn btn-primary" />
</form>
and here is the script I am using:
$ie = New-Object -ComObject "internetExplorer.Application"
$ie.Visible = $true
$ie.Navigate("https://mywebsite.ca/ms/Login.aspx?appId=8");
while ($ie.Busy -eq $true){Start-Sleep -Milliseconds 1000;}
Write-Host -ForegroundColor Magenta "Attempting to login";
$doc = $ie.Document
$LoginName = $doc.getElementsByTagName("usernameTxt")
$LoginName.value = "MyUserID"
$txtPassword = $doc.getElementsByName("passwordTxt")
$txtPassword = "MyPassword"
$btnLogin = $doc.getElementsByName("tryLoginBtn")