html - 使用 powershell 单击网页上的链接,然后传递凭据

标签 html powershell automated-tests

我正在尝试测试我们构建的具有临时 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/

相关文章:

windows - 在 powershell 中使用不同的分隔符和引号导入 csv

powershell - 如何在Powershell中转义 "and '的混合物?

powershell - 使用带步骤的范围运算符

batch-file - 如何重构充满 GOTO 的 Windows 批处理脚本?

html - 相对的和绝对的;响应中心定位? Bootstrap CSS

html - iframe 内容在 chm 文件中不可见

jquery - 视差滚动背景上的水平滚动注册表格

html - 居中和右对齐flexbox元素

docker - 在 Cypress 中运行 Docker 容器时出现问题

javascript - 如何使用 cypress.io 检查嵌套的阴影元素