2013-03-06 100 views
-1

我正在尝试将我的凭据放入网站,以便自动执行一些任务。我正在尝试这个代码。没有任何反应。故障自动化Internet Explorer

$Url = "https://srvdcvs05.fiep_pr.br:1311/" 
$Ie = New-Object -Com InternetExplorer.Application 
$Ie.Navigate($Url) 
$secLink = $Ie.Document.getElementsByTagName('A') | Where-Object {$_.innerText -eq 'Continue to this website (not recommended).'} 
$secLink.click() 
$Ie.Document.getElementsByType("input") | where { $.Name -eq "user" }.value = "myuser" 
$Ie.Document.getElementsByName("input") | where { $.Name -eq "password" }.value = "mypassword" 
$loginBtn = $Ie.Document.getElementsById('input') | Where-Object {$_.Type -eq 'button' -and $_.Value -eq 'LoginButton'} 
$loginBtn.click() 

回答

1

很难说不知道页面的任何内容。

话虽这么说,两个明显的错误,可能是这个原因吧:

# Your code: $Ie.Document.getElementsByType("input") | where { $.Name -eq "user" }.value = "myuser" 
($Ie.Document.getElementsByType("input") | where { $_.Name -eq "user" }).value = "myuser" 
# Your code: $Ie.Document.getElementsByName("input") | where { $.Name -eq "password" }.value = "mypassword" 
($Ie.Document.getElementsByName("input") | where { $_.Name -eq "password" }).value = "mypassword" 

所以:访问属性脚本块没有意义({ }.value)和where需求$_.Property而非$.Property

1

感谢您的重播。

关于它“$ _。Property而不是$ .Property。”打错了,对此感到遗憾。

但是...我最初的问题是这样的功能:

$ secLink = $ Ie.Document.getElementsByTagName( 'A')|位置对象{$ _。innerText属性-eq '继续浏览此网站(不推荐)。'}

$ secLink.click()

不起作用。该网站打开,但没有点击此消息。