【发布时间】:2014-01-15 19:14:59
【问题描述】:
我试图弄清楚如何在 Windows 7 x64 上使用 PowerShell 版本 2 登录 Internet Explorer 9 中的网页。当我在 PowerShell 中一一运行这些行时,我得到了我想要的 - 页面打开并且我能够登录。
$internet_explorer = new-object -com "InternetExplorer.Application"
$internet_explorer.visible = $true
$internet_explorer.navigate2("https://abcd.efgh.com/ijkl/Login.jsp")
$this_document = $internet_explorer.document
$username_field = $this_document.getElementByID("usernameField")
$password_field = $this_document.getElementByID("passwordField")
$login_button = $this_document.getElementByID("SubmitButton")
$username_field.value = "username"
$password_field.value = "password"
$login_button.click()
但是当我尝试打开另一个选项卡并尝试通过一一执行以下行来登录新网页时,
$internet_explorer.navigate2("https://mnop.qrst.com/uvwx/Login.jsp", 0x0800)
$this_document = $internet_explorer.document
$username_field = $this_document.getElementByID("usernameField")
$password_field = $this_document.getElementByID("passwordField")
$login_button = $this_document.getElementByID("SubmitButton")
$username_field.value = "username"
$password_field.value = "password"
$login_button.click()
我收到以下错误:
Property 'value' cannot be found on this object; make sure it exists and is settable.
At line:1 char:17
+ $username_field. <<<< value = "username"
+ CategoryInfo : InvalidOperation: (value:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
Property 'value' cannot be found on this object; make sure it exists and is settable.
At line:1 char:17
+ $password_field. <<<< value = "password"
+ CategoryInfo : InvalidOperation: (value:String) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
You cannot call a method on a null-valued expression.
At line:1 char:20
+ $login_button.click <<<< ()
+ CategoryInfo : InvalidOperation: (click:String) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
那么当我打开一个新标签时,我如何才能获得那个新打开的标签的Document?请帮我解决这个问题
编辑:替代方法可以。如果它们存在,请随意建议任何其他方式来自动登录多个网页(如上面尝试的方式)
【问题讨论】:
标签: windows internet-explorer powershell automation