c3uba9wfaq
c3uba9wfaq

Reputation: 83

Powershell Automate Site Logon

I am looking to automate the logon to a phpBB site.

So I have been able to automate the navigation, username, password, and even a check box. However, I need to be able to "click" the logon button.

Here is the site code pertaining to the "Login" button:

   <form action="http://www.somethingorother.com/login.php" method="POST" onsubmit="return validateOwnerLogin()" >
    <table width="100%" cellpadding="5" cellspacing="0" border="0">

   <tr>
    <td width="30%" align="right" valign="top">
     Login
    </td>
    <td width="70%" align="left" valign="top">
     <input type="text" size="45" name="login" maxlength="50">
    </td>
   </tr>

   <tr>
    <td width="30%" align="right" valign="top">
     Password (min 4 characters)
    </td>
    <td width="70%" align="left" valign="top">
     <input type="password" size="45" name="password" maxlength="50">
    </td>
   </tr>

   <tr>
    <td width="30%" align="right" valign="top">
     <input type="checkbox" name="terms_read" value="yes">
    </td>
    <td width="70%" align="left" valign="top">
     By using this Login window, I agree to the Terms and Conditions.
    </td>
   </tr>

   <tr>
    <td width="30%" align="right" valign="top">

    </td>
    <td width="70%" align="left" valign="top">
     <input type="submit" value="Login">
    </td>
   </tr>

From digging around I have figure out that the "login" value might be the issue here because there are more than one. I have tried the .click() and .submit() attempts.

Always end up with:

You cannot call a method on a null-valued expression.
At line:12 char:1
+ $submitButton = $doc.getElementById('Login')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

Can I even do this with IE and hints as how? Or is there an alternative with Invoke-WebRequest?

Upvotes: 1

Views: 396

Answers (1)

c3uba9wfaq
c3uba9wfaq

Reputation: 83

The key was this block on the html:

 </td>
    <td width="70%" align="left" valign="top">
     <input type="submit" value="Login">
    </td>
   </tr>

Obviously there is no "ID" to work with. However, utilizing .getElementsByTagName I could specify this one.

Here is the code I used to "click" the Login button.

$Link=$ie.Document.getElementsByTagName("input") | where-object {$_.type -eq "submit"}
$Link.click()

Upvotes: 1

Related Questions