none
Open Internet explorer 8 (and its tabs) using Powershell? RRS feed

  • Question

  • Hi,

    Is there a way to open Internet explorer 8 using Powhershell, and then pass userName/pwd to the site opened in IE (I think it can be passed with the URL). 

    I m trying to automate my website testing, where I need to open at least 5 IE windows(5 tabs in IE8 single instance), each with a unique user/password,  on 2 of my client machines.

    Thanks in advnace.

    Regards,


    Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com
    Friday, August 13, 2010 12:27 PM

Answers

All replies

  • You can do the tabs part like this:

    $ie = New-Object -ComObject InternetExplorer.Application
    $ie.Navigate2("www.microsoft.com")
    $ie.Navigate2("www.microsoft.com",0x1000)
    $ie.Navigate2("www.microsoft.com",0x1000)
    $ie.Navigate2("www.microsoft.com",0x1000)
    $ie.Navigate2("www.microsoft.com",0x1000)
    $ie.Visible = $true

    Passwords are trickier.

    See here for inspiration:

    http://www.youdidwhatwithtsql.com/automating-internet-explorer-with-powershell/467

    Karl


    http://unlockpowershell.wordpress.com
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    • Marked as answer by Laeeq Qazi Monday, August 16, 2010 9:44 PM
    Friday, August 13, 2010 3:32 PM
  • Hi,

    Excellent Karl. Thanks alot. Your script satisfies half of my requirement. 

    I m now searching how to pass userName/Password to the website, which i m testing.

    I have also found this nice article

    Test Run: Web UI Automation with Windows PowerS.

    http://msdn.microsoft.com/en-us/magazine/cc337896.aspx


    In the link you posted I am a little confused about this ps line:

    $ie.Document.getElementById("username_or_email").value = $username_or_email;

    How can I get the Document of other tabs, I think above line only gets Document of first IE tab.

    Thanks and Regards,


    Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com
    Friday, August 13, 2010 9:19 PM
  • Laeeq;

    You will probally have to use send keys to switch tabs, from that point, perhaps the password stuff may work

    Karl


    http://unlockpowershell.wordpress.com
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    Friday, August 13, 2010 10:34 PM
  • Hi,

    Karl thanks alot for replying to this thread.

    IF we go to this page http://msdn.microsoft.com/en-us/library/aa752084(VS.85).aspx and read the definition of Document property of IE object we can see that it always represent the Active Document. By Active I think it means the tab which is  foreground tab.

    I have found an interesting flag here http://msdn.microsoft.com/en-us/library/dd565688(v=VS.85).aspx  to be passed to Navigate2() method, which is 65536 (instead of 2048 or 0x1000)

    navOpenNewForegroundTab (65536)

    Internet Explorer 8 and later. Open the resource in a new tab that becomes the foreground tab.

    So I think if I open the first url in IE8 and then get the fields name and process them , and then open another tab in foreground and process it, and then move forward to other Tabs similarly.

    So i will try it today later, and will post the result here.

    Regards,


    Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com
    • Marked as answer by Laeeq Qazi Monday, August 16, 2010 9:44 PM
    Friday, August 13, 2010 11:54 PM
  • Hi,

    Unfortunately this 0x10000 (65536) is not working with Navigate or Navigate2()

    $ie.Navigate("www.microsoft.com",0x10000)

    OR

    $ie.Navigate2("www.microsoft.com",0x10000)

    While this 0x10000 (65536) is mentioned on this link http://msdn.microsoft.com/en-us/library/dd565688(v=VS.85).aspx but I am not able to use it with Navigate() or Navigate2(). The tab is never being created if I pass 0x10000.

     

    Anyone there to comment on this?

    Regards,


    Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com
    Saturday, August 14, 2010 8:07 PM
  • Laeeq;

    If I do the following, Xerox.com is the foreground tab (And, tab 0):

    $ie = New-Object -ComObject InternetExplorer.Application
    $ie.Navigate2("www.microsoft.com")
    $ie.Navigate2("www.microsoft.com",0x1000)
    $ie.Navigate2("www.xerox.com",0x10000)
    $ie.Navigate2("www.microsoft.com",0x1000)
    $ie.Navigate2("www.microsoft.com",0x1000)
    $ie.Visible = $true
    
    Karl
    http://unlockpowershell.wordpress.com
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    Monday, August 16, 2010 1:50 PM
  • Laeeq;

    If I do the following, Xerox.com is the foreground tab (And, tab 0):

    $ie = New-Object -ComObject InternetExplorer.Application
    $ie.Navigate2("www.microsoft.com")
    $ie.Navigate2("www.microsoft.com",0x1000)
    $ie.Navigate2("www.xerox.com",0x10000)
    $ie.Navigate2("www.microsoft.com",0x1000)
    $ie.Navigate2("www.microsoft.com",0x1000)
    $ie.Visible = $true
    
    Karl
    http://unlockpowershell.wordpress.com
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

    Hi,

    Karl thanks a bundle for your reply. Yes u r 110% right. 

    $ie.Navigate2("www.xerox.com",0x10000)

    indeed opens a URL in a new tab and makes it a foreground tab.

    Regards,


    Laeeq Qazi|Team Lead(Exchange + Sharepoint + BES + DynamicsCRM) www.HostingController.com
    Monday, August 16, 2010 9:41 PM
  • I've looked over the link below trying to find the difference between the Navigate and Navigate2 methods.

    http://msdn.microsoft.com/en-us/library/aa752084(v=vs.85).aspx

    Navigate - Navigates to a resource identified by a URL or to a file identified by a full path.

    Navigate2 - Navigates the browser to a location that might not be expressed as a URL, such as a pointer to an item identifier list (PIDL) for an entity in the Windows Shell namespace.

    In the examples above since you are dealing with URL's that Navigate would be the natural choice but all of the examples I've found here and elsewhere on the net use Navigate2.

     

    Can anyone explain?

    Friday, April 22, 2011 7:46 PM
  • Well, Navigate2 shows:

    This method extends the Navigate method to allow for Shell integration; however, this method does not make Navigate obsolete. The original method can still be used for URL navigations.

    Yes, the examples I used were all URL's which would work with Navigate.

    However, by using Navigate2, my example is not limited to URL's.

    Karl


    http://unlockpowershell.wordpress.com
    Co-Author, Windows PowerShell 2.0 Bible
    -join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})
    Monday, April 25, 2011 9:02 PM