<button type="submit">Login</button>
I am trying to click/submit the above button using Windows Powershell. I have tried the following code:
$submitButton = $doc.documentElement.getElementsByClassName('button') |
Select-Object -First 1
$submitButton.click()
which brings back this error:
You cannot call a method on a null-valued expression.
ps1:15 char:1
+ $submitButton = $doc.documentElement.getElementsByClassName('button') | ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
You cannot call a method on a null-valued expression.
ps1:16 char:1
+ $submitButton.click()
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
I also tried this code:
$loginBtn = $ie.Document.getElementsById('input') |
Where-Object {$_.Type -eq 'button' -and $_.Value -eq 'LoginButton'}
$loginBtn.click()
but this also brings back the same error as before.
my powershell code in full:
$username='USERNAME'
$password='PASSWORD'
$ie = New-Object -ComObject 'internetExplorer.Application'
$ie.Visible= $true
$ie.Navigate("URL EXAMPLE")
while ($ie.Busy -eq $true){Start-Sleep -seconds 1;}
$Open = $ie.Document.getElementByID('has-account')
$Open.click()
$usernamefield = $ie.Document.getElementByID('login-usr').value = $username
$passwordfield = $ie.Document.getElementByID('login-pass').value = $password
$submitButton = $doc.documentElement.getElementsByClassName('button') | Select-Object -First 2
$submitButton.click()
EDIT
Here is the output of powershell getelementbytagname. Notice there is no classname or ID, how does it get clicked?
className :
id :
tagName : BUTTON
parentElement : System.__ComObject
style : System.__ComObject
document : mshtml.HTMLDocumentClass
sourceIndex : 60
offsetLeft : 61
offsetTop : 220
offsetWidth : 320
offsetHeight : 41
offsetParent : System.__ComObject
innerHTML : Login
innerText : Login
outerHTML : <button type="submit">Login</button>
outerText : Login
parentTextEdit : System.__ComObject
EDIT
<form id="sp-login-form" action="#" method="post">
<button type="button" id="fb-login-btn" class="button fb">Log in with Facebook<span style="position: absolute;"></span></button>
<em>or</em>
<div>
<label for="login-usr">Username</label>
<input type="text" name="username" id="login-usr" placeholder="Spotify username">
<label for="login-pass" class="pass">Password</label>
<input type="password" name="password" id="login-pass" class="pass" placeholder="Password">
<button type="submit">Login</button>
</div>
</form>
$docand$iecome from? - Mathias R. Jessen