Jump to content

Does IE Window Exist?


tuffgong
 Share

Recommended Posts

I give the user an option to start 5 different web pages through a GUI. Then I want to manipulate the pages they have chosen to open. First, I need to see which pages they have chosen to open. I suppose I could just create a Boolean solution; when they choose a page set it to True, but isn't there a way to check if a page exists? I copied the code below right from the WinExists help file, added IE to it, and it appears to do the opposite! If the page is open the message says "Window does not exist" and for the check that does not exist I get "Window exists"! What is the best way to see if the user has activated $oIE1, $oIE2, $oIE3, etc.?

#include <MsgBoxConstants.au3>
#include <IE.au3>

Global $oIE2, $oIE3

Example()

Func Example()
    $oIE3 = _IECreate("www.google.com")

    ; Wait 10 seconds for the Notepad window to appear.
    Sleep(10000)

    ; Test if the window exists and display the results.
    If WinExists($oIE3) Then
        MsgBox($MB_SYSTEMMODAL, "1", "Window exists")
    Else
        MsgBox($MB_SYSTEMMODAL, "1", "Window does not exist")
    EndIf
    If WinExists($oIE2) Then
        MsgBox($MB_SYSTEMMODAL, "2", "Window exists")
    Else
        MsgBox($MB_SYSTEMMODAL, "2", "Window does not exist")
    EndIf
EndFunc   ;==>Example

 

Link to comment
Share on other sites

_IECreate returns an object, however WinExists requires a handle. As to your second problem, it seems that calling WinExists with an empty string (or an unassigned variable in your case) for the Window Name always returns True. If you set it to 0 it won't say that the window exists.

 

#include <MsgBoxConstants.au3>
#include <IE.au3>

Global $oIE2 = 0, $oIE3 = 0

Example()

Func Example()
    $oIE3 = _IECreate("www.google.com")
    $hWnd = _IEPropertyGet($oIE3, "hwnd")

    ; Wait 10 seconds for the Notepad window to appear.
    Sleep(10000)

    ; Test if the window exists and display the results.
    If WinExists($hWnd) Then
        MsgBox($MB_SYSTEMMODAL, "1", "Window exists")
    Else
        MsgBox($MB_SYSTEMMODAL, "1", "Window does not exist")
    EndIf
    If WinExists($oIE2) Then
        MsgBox($MB_SYSTEMMODAL, "2", "Window exists")
    Else
        MsgBox($MB_SYSTEMMODAL, "2", "Window does not exist")
    EndIf
EndFunc   ;==>Example

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...