我正在尝试测试我们构建的具有临时 ssl 证书的网页,问题是当我转到该页面时,我收到 IE 安全警告,指出 ssl 证书无效,有两个链接,一个用于关闭页面,另一个继续页面。我能够使用 powershell 打开 IE 并单击 ssl 警告页面上的链接,但现在我需要填充用户名和密码输入框,然后单击登录按钮。
$url = "res://ieframe.dll/invalidcert.htm?SSLError=50331648#https://10.2.2.1:8050/showme.do"
$ie = New-Object -comobject InternetExplorer.Application
$ie.visible = $true
$ie.silent = $true
$ie.Navigate( $url )
while( $ie.busy){Start-Sleep 1}
$secLink = $ie.Document.getElementsByTagName('A') | Where-Object {$_.innerText - eq 'Continue to this website (not recommended).'}
$secLink.click()
$ie.Document.getElementsByType("input") | where { $.Name -eq "j_username" }.value = "user"
$ie.Document.getElementsByName("input") | where { $.Name -eq "j_password" }.value = "password"
$loginBtn = $ie.Document.getElementsById('input') | Where-Object {$_.Type -eq 'button' -and $_.Value -eq 'LoginButton'}
$loginBtn.click()
现在页面打开但输入字段未填充或按钮未单击,我需要某种循环或 while 语句吗?
谢谢
最佳答案
当您点击链接时,您需要等到页面完成加载。
$url = "res://ieframe.dll/invalidcert.htm?SSLError=50331648#https://10.2.2.1:8050/showme.do"
$ie = New-Object -comobject InternetExplorer.Application
$ie.visible = $true
$ie.silent = $true
$ie.Navigate( $url )
while( $ie.busy){Start-Sleep 1}
$secLink = $ie.Document.getElementsByTagName('A') | Where-Object {$_.innerText - eq 'Continue to this website (not recommended).'}
$secLink.click()
while( $ie.busy){Start-Sleep 1}
$ie.Document.getElementsByType("input") | where { $.Name -eq "j_username" }.value = "user"
$ie.Document.getElementsByName("input") | where { $.Name -eq "j_password" }.value = "password"
$loginBtn = $ie.Document.getElementsById('input') | Where-Object {$_.Type -eq 'button' -and $_.Value -eq 'LoginButton'}
$loginBtn.click()
关于html - 使用 powershell 单击网页上的链接,然后传递凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10436332/