【发布时间】:2016-04-22 15:42:12
【问题描述】:
我正在尝试让我的 powershell 脚本单击网站上的以下对象。
源代码:
<a onclick="document.selectAccountsGroupsForm.action='manageAccountsGroups.do?method=showAllAccounts';document.selectAccountsGroupsForm.submit();">
<img alt="showAllAccounts" src="/TNE/images/common/buttons/btn_showAllAccounts.gif">
</a>
<input name="accountSelectionCBChecked" type="hidden" value="false">
Powershell 代码
$ie = new-object -Com InternetExplorer.Application;
$ie.visible = $true;
$ie.navigate($url);
while($ie.busy) {Start-Sleep -Milliseconds 1000;}
$ie.Document.getElementById(“userName”).value = $Username
$ie.Document.getElementByID(“password”).value = $Password
$ie.Document.getElementById(“loginBtn”).Click()
$link=$ie.Document.getElementsByTagName('A') | Where-Object {$_.href -eq "document.selectAccountsGroupsForm.action='manageAccountsGroups.do?method=showAllAccountGroups';document.selectAccountsGroupsForm.submit();"}
$link.click()
注意:用户名、密码和 URL 变量未发布
错误
You cannot call a method on a null-valued expression.
At H:\Desktop\Scripts\TEST.ps1:56 char:1
+ $link.click()
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull –
【问题讨论】:
-
您发布的代码有什么问题? IE是唯一可以使用的浏览器吗?
-
是的,我只能使用 IE,因为我正在使用这个脚本工作。我遇到的问题是我需要脚本单击一个名为“显示所有帐户”的按钮,单击该按钮时会按照它说的那样进行
-
你发布的代码怎么不起作用?
-
当我在 Windows Powershell 上运行代码时,我收到以下错误:您不能在空值表达式上调用方法。在 H:\Desktop\Scripts\TEST.ps1:56 char:1 + $link.click() + ~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
-
您应该在原始帖子中发布异常等详细信息,而不是几天后在评论中发布。
标签: java html css powershell