Reputation: 144
I am trying to figure out how to login to web-pages in Internet Explorer 9 using PowerShell version 2 on Windows 7 x64. When I run these lines one by one in PowerShell, I get exactly what I want - The page opens and I am able to login.
$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()
But when I try to open another tab and try to login to the new webpage by executing the below lines one-by-one,
$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()
I get the following errors :
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
So when I open a new tab, how can I get Document
of that newly opened tab? Please help me solve this
EDIT : Alternative methods will do. Please feel free to suggest any other way to login to multiple web pages automatically (like what was attempted above) if they exist
Upvotes: 0
Views: 1373
Reputation: 24545
From the documentation for the Navigate method, it would appear that the new tab is not available for automation:
When navOpenInNewWindow or navOpenInNewTab is specified, the caller does not receive a pointer to the IWebBrowser2 interface for the new window, so there is no immediate way to manipulate it.
Upvotes: 0