简体   繁体   中英

powershell can't click a button

i wanted to start my journey with powershell, but it seems I can't figure out why button on this site is not responding

https://s1.wcy.wat.edu.pl/ed/

(this is my uni site)

I want to be able to sign in via script.

I've been trying different variations like

$submitButton = $ie.documentElement.getElementsByTagName("input") | Where-Object {$_.value -eq ' Zaloguj się '} $submitButton.click()

or

$submitButton = $ie.documentElement.getElementsByTagName("input") | Where-Object {$_.type -eq 'submit'} $submitButton.click()

but i always get error.

You cannot call a method on a null-valued expression

What am I missing?

Try it this way...

$ie = New-Object -com InternetExplorer.Application 
$ie.visible=$true
$ie.navigate('https://s1.wcy.wat.edu.pl/ed') 

while($ie.ReadyState -ne 4) {start-sleep -m 100}

$UserID = $ie.document.getElementsByTagName('INPUT') | 
Where-Object {$($_.Name) -match 'userid'}
$UserId.value = 'UserID'

$UserPassword = $ie.document.getElementsByTagName('INPUT') | 
Where-Object {$($_.Name) -match 'password'}
$UserPassword.value = 'password'

$Submit = $ie.document.getElementsByTagName('INPUT') | 
Where-Object {$($_.Value) -match 'Zaloguj'}
$Submit.click()

Since scraping this, the INPUT was more reliable, since they all are INPUT tags.

$wcy = Invoke-WebRequest -Uri 'https://s1.wcy.wat.edu.pl/ed'
$wcy.Forms[0] | Format-List -Force
$wcy.Forms[0].Fields
$wcy.InputFields

I just tested this, so I know it works. Well, it did for me. Well, of course the login in failed due to invalid creds. ;-}

You were not getting a match (that error message) with the -eq due to the string not being read as expected. Using match worked better.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM