我需要填写一个内部网站的表格。我可以使用此代码成功登录门户网站页面
selectedPosition: number;
removeSelectedRows() {
this.dataSource.data = this.dataSource.data.filter(element => element.position !== this.selectedPosition);
}
以上工作正常。它会将我定向到需要填写另一张表格的新链接。因此,我在重复使用上面的代码来填写用户字段和提交按钮的表单。
此页面内有多种形式,因此我想将其范围缩小到特定的$ie = New-Object -Com InternetExplorer.Application
$ie.Visible = $true
$ie.Navigate("https://some-internal-ip/login")
while ($ie.ReadyState -ne 4) {Start-Sleep -m 100};
#Login
$form = $ie.document.forms[0]
$inputs = $form.GetElementsByTagName("input")
($inputs | where {$_.Name -eq "username"}).Value = $username
($inputs | where {$_.Name -eq "password"}).Value = $password
($inputs | where {$_.Name -eq "action:Login"}).Click()
#after login - navigate to this link
while ($ie.ReadyState -ne 4 -or $ie.Busy) {Start-Sleep -m 100}
Start-Sleep -m 2000
$ie.Navigate("https://some-internal-ip/monitor/users")
。
HTML表单:
id="trackingSearchForm"
获取表格ID并填写
<form action="https://.../" method="POST" name="trackingSearchForm" id="trackingSearchForm" accept-charset="utf-8" onsubmit="return false;">
<input name="user" onkeypress="keyPressHandler(this.form, event)" class="" type="text" id="user" value=">
<input type="button" class="submit" id="submitButton" value="Search" onclick="performSearch();">
但是我遇到了这些错误:
You cannot call a method on a null-valued expression. + $inputs = $form.GetElementsByTagName("input") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull The property 'value' cannot be found on this object. Verify that the property exists and can be set. + ($inputs | where {$_.Name -eq "user"}).Value = "john" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound
我用于登录表单的相同代码在其他表单上不起作用。
答案 0 :(得分:0)
错误可能在这一行:
Add-LocalGroupMember -Name "Cert Publishers" -Member domain\myUserAccount
删除索引-Name
:
$form = ($ie.document.forms[0] | where {$_.id -eq "trackingSearchForm"})