我是PowerShell的新手。当我尝试执行以下代码时,出现错误:
“在语句块或类型定义中缺少结束 '}'。”
下面是代码,我不确定我在哪里失踪。
$path = "C:\Users\Dr.Salya\Downloads"
$filename = "rateonlyl-455.zip"
$url = "https://vertexinc.custhelp.com/app/utils/login_form"
$url2 = "https://download-ie.flexnetoperations.com/512175/1386/77/17129077/rateonlyl-455.zip?ftpRequestID=2321180473&server=download-ie.flexnetoperations.com&dtm=DTM20200820125043ODA0MDU5NDEz&authparam=1597953043_bf5ca04b9a74eeb53a272c20ea148517&ext=.zip/"
$ie = New-Object -com InternetExplorer.Application
$ie.visible = $true
$ie.silent = $false
$ie.navigate("$url")
while($ie.ReadyState -ne 4){start-sleep -m 100}
if ($ie.document.url -Match "invalidcert"){
$sslbypass=$ie.Document.getElementsByTagName("a") | where-object {$_.id -eq "overridelink"}
$sslbypass.click()
start-sleep -s 5
}
$ie.Document.IHTMLDocument3_getElementById("username").click()
$ie.Document.IHTMLDocument3_getElementById("username").value ='********'
$ie.Document.IHTMLDocument3_getElementById("password").click()
$ie.Document.IHTMLDocument3_getElementById("password").value ='1234'
$ie.Document.IHTMLDocument3_getElementById("").click()
start-sleep 5
$ie.navigate($url2)
start-sleep 10
$ie.Document.body.outerHTML | Out-File -FilePath $path/$filename
错误:
You cannot call a method on a null-valued expression.
At C:\Users\Dr.Salya\Downloads\Vertex1.ps1:22 char:1
+ $ie.Document.IHTMLDocument3_getElementById("username").click()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At C:\Users\Dr.Salya\Downloads\Vertex1.ps1:23 char:1
+ $ie.Document.IHTMLDocument3_getElementById("username").value ='nnaisv ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At C:\Users\Dr.Salya\Downloads\Vertex1.ps1:24 char:1
+ $ie.Document.IHTMLDocument3_getElementById("password").click()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
The property 'value' cannot be found on this object. Verify that the property exists and can be set.
At C:\Users\Dr.Salya\Downloads\Vertex1.ps1:25 char:1
+ $ie.Document.IHTMLDocument3_getElementById("password").value ='Vertex ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At C:\Users\Dr.Salya\Downloads\Vertex1.ps1:26 char:1
+ $ie.Document.IHTMLDocument3_getElementById("").click()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
您必须抓取页面以确保获得正确的对象/元素并一次执行一个用例。以及对象/元素是否具有解决用例所需的属性和方法。
例如,只是让登录的东西工作。
...然后像本网站一样转到下一页(如果有)。然而,由于我没有在此站点上使用的帐户,因此我无法执行和进一步的操作。然而,即使从登录页面中提取链接列表,对于任何后续页面都是相同的。
最后一件事,您可以自动化允许它的站点。一些站点不允许对其属性(或其中的一部分)进行自动化,它们会主动对其进行编码以防止它发生。