Share this page 

Use Internet ExplorerTag(s): WinAPI/Registry


  • Method #1 - Using HyperlinkToURL function

  • Needs PB6.5 or better. Starts the default browser as defined in your installation.
    string ls_url
    inet iinet_base
    
    ls_url = "http://wwww.server.com/myWebApp?file=error.log"
    GetContextService("Internet", iinet_base)
    iinet_base.HyperlinkToURL(ls_url)
    
  • Method #2 - Using OLEObject InternetExplorer.Application + Run
    OLEObject IE
    string ls_ie
    string ls_url
    
    IE = CREATE OLEObject
    IE.ConnectToNewObject("InternetExplorer.Application")
    
    ls_ie = IE.Fullname ()
    
    ls_url = "http://wwww.server.com/myWebApp?file=error.log"
    Run (ls_ie + " " + ls_url)
    
  • Method #3 - Using OLEObject InternetExplorer.Application

  • Provides complete control IE behaviour.
    OLEObject IE
    
    IE = CREATE OLEObject
    IE.ConnectToNewObject("InternetExplorer.Application")
    
    IE.left=200
    IE.top=200
    IE.height=400
    IE.width=400
    IE.menubar=0
    IE.toolbar=1
    IE.statusBar=0
    IE.navigate("http://wwww.server.com/myWebApp?file=error.log")
    IE.visible=1
    
    // Local external function decalration
    // FUNCTION boolean SetForegroundWindow( long hWnd ) LIBRARY "USER32"
    SetForegroundWindow( IE.HWND )
    
  • Method 4 - Using OLEObject InternetExplorer.Application
    Provides complete control IE behaviour. You simulate a FORM submit.using the POST method.
    OLEObject IE
    
    IE = CREATE OLEObject
    IE.ConnectToNewObject("InternetExplorer.Application")
    
    IE.left=200
    IE.top=200
    IE.height=400
    IE.width=400
    IE.menubar=0
    IE.toolbar=1
    IE.statusBar=0
    IE.goHome
    IE.visible=1
    
    
    DO WHILE IE.busy
    LOOP
    
    IE.document.Open
    IE.document.WriteLn("<HTML><HEAD>")
    IE.document.WriteLn("<SCRIPT>")
    IE.document.WriteLn("function go() {")
    IE.document.WriteLn("  document.myform.submit()")
    IE.document.WriteLn("  }")
    IE.document.WriteLn("</SCRIPT>")
    IE.document.WriteLn("</HEAD>")
    IE.document.WriteLn("<BODY onload='go()'>")
    IE.document.WriteLn("<FORM name='myform' ")
    IE.document.WriteLn("METHOD='GET' ACTION='http://server.com/myApp'>")
    IE.document.WriteLn("<INPUT NAME='file' TYPE=HIDDEN VALUE='error.log'>")
    IE.document.WriteLn("</FORM>")
    IE.document.WriteLn("</BODY>")
    IE.document.WriteLn("</HTML>")
    IE.document.Close
    
    // Local external function declaration
    // FUNCTION boolean SetForegroundWindow( long hWnd ) LIBRARY "USER32"
    SetForegroundWindow( IE.HWND )
    
    
    // IE.Quit()
    // IE.DisconnectObject()
    // DESTROY iBrowser
    
    

    Some tips from rkern (thanks to him!).

    Some handy properties:

    IE.top = <integer>
    IE.left = <integer>
    IE.width = <integer>
    IE.height = <integer>
    IE.visible = <integer> (1 - Visible/ 0 - Not Visible)
    IE.menuBar = <integer> (1 - Visible/ 0 - Not Visible)
    IE.toolBar = <integer> (1 - Visible/ 0 - Not Visible)
    IE.statusBar = <integer> (1 - Visible/ 0 - Not Visible)
    

    Go To a URL:

    string ls_OldURL
    string ls_NewURL = 'www.yahoo.com'
    // Go to Document
    ls_OldURL = IE.LocationURL
    IE.Navigate (ls_NewURL)
    // Wait for Document to start loading
    DO WHILE ls_OldURL = IE.LocationURL
      Yield ()
    LOOP
    // Wait for Document to finish Loading
    DO WHILE IE.Busy
     Yield ()
    LOOP
    
    Notes:
    -The Busy attribute does not always get set immediateley so wait for URL to change before checking the Busy attribute
    - This method works as long as the OldURL and NewURL are not the same

    Click on a Link with a specific display text:

    integer li_link, li_link_ctr
    string ls_text, ls_OldURL, ls_search = 'Download Spreadsheet'
    // Set Match string
    ls_search = Upper(ls_search)
    // Find Link with specified Text
    li_link_ctr = IE.Document.Links.Length
    FOR li_link = 0 TO li_link_ctr - 1
      ls_Text = Upper(IE.Document.Links[li_link].InnerText)
      // Check for Match
      IF ls_Text = as_Search THEN
          // Click the Link
          ls_OldURL = IE.LocationURL
          IE.Document.Links[li_link].Click()
          // Wait for Document to start loading
          DO WHILE ls_OldURL = IE.LocationURL
             Yield ()
          LOOP
          // Wait for Document to finish loading
          DO WHILE IE.Busy
            Yield ()
          LOOP
          EXIT
      END IF
    NEXT
    
    Notes:
    - The Busy attribute does not always get set immediateley so wait for URL to change before checking the Busy attribute
    - This method works as long as the OldURL and NewURL are not the same - Unlike PB, arrays start at index = 0 to length - 1 - Use attribute HRef if you want to match on a URL

    Click on a Button with a specific display text:

    integer li_form, li_form_ctr
    integer li_elem, li_elem_ctr
    boolean lb_stop
    string ls_text, ls_OldURL, ls_search = 'Search'
    any la_name, la_type, la_value
    // Set Match string
    ls_search = Upper(ls_search)
    // Search thru Forms
    li_form_ctr = IE.Document.Forms.Length
    FOR i = 0 TO li_form_ctr - 1
        // Search thru Elements
        li_elem_ctr = IE.Document.Forms[i].Elements.All.Length
        FOR j = 0 TO li_elem_ctr - 1
            la_Name =
              IE.Document.Forms[i].Elements.All[j].GetAttribute("name")
            la_Type =
              IE.Document.Forms[i].Elements.All[j].GetAttribute("type")
            la_Value =
              IE.Document.Forms[i].Elements.All[j].GetAttribute("value")
            CHOOSE CASE Upper(String(la_Type))
            CASE 'SUBMIT', 'RESET', 'BUTTON'
                ls_Text = Upper(String(la_Value))
                // Check for Match
                IF ls_Text = ls_Search THEN
                    // Click the Button
                    ls_OldURL = IE.LocationURL
                    IE.Document.Forms[i].Elements.All[j].Click()
                    // Wait for Document to start loading
                    DO WHILE ls_OldURL = IE.LocationURL
                       Yield ()
                    LOOP
                    // Wait for Document to finish loading
                    DO WHILE IE.Busy
                       Yield ()
                    LOOP
                    lb_Stop = TRUE
                    EXIT
                END IF
            END CHOOSE
        NEXT
        IF lb_Stop THEN
           EXIT
        END IF
    NEXT
    
    Notes:
    - The Busy attribute does not always get set immediateley so wait for URL to change before checking the Busy attribute
    - This method works as long as the OldURL and NewURL are not the same
    - Unlike PB, arrays start at index = 0 to length - 1
    - Use attribute Name if you want to match on an internal HTML Name
    - The Returned Values of the GetAttribute method must be ANY variables , even though they return STRINGS

    Fill in a Input Field that has a specific Name:

    integer li_form, li_form_ctr
    integer li_elem, li_elem_ctr
    boolean lb_Stop
    string ls_text, ls_search = 'Company'
    any la_name, la_type, la_value
    // Set Match string
    ls_search = Upper(ls_search)
    // Search thru Forms
    li_form_ctr = IE.Document.Forms.Length
    FOR i = 0 TO li_form_ctr - 1
        // Search thru Elements
        li_elem_ctr = IE.Document.Forms[li_form].Elements.All.Length
        FOR j = 0 TO li_elem_ctr - 1
            la_Name =
              IE.Document.Forms[i].Elements.All[j].getAttribute("name")
            la_Type =
              IE.Document.Forms[i].Elements.All[j].getAttribute("type")
            la_Value =
              IE.Document.Forms[i].Elements.All[j].getAttribute("value")
            // ls_Text = IE.Document.Forms[i].Elements.All[j].InnerText
    
            CHOOSE CASE Upper(String(la_Type))
            CASE 'TEXT', 'TEXTAREA', 'PASSWORD'
                ls_Text = Upper(String(la_Name))
                // Check for Match
                IF ls_Text = ls_Search THEN
                    // Set the value
                    IE.Document.Forms[i].Elements.All[j].Value = ls_Value
                    lb_Stop = TRUE
                    Exit
                END IF
            END CHOOSE
        NEXT
        IF lb_Stop THEN
           Exit
        END IF
    NEXT
    
    Notes:
    - Unlike PB, arrays start at index = 0 to length - 1
    - Use attribute InnerText if you want to match on a percieved label on the field. Check each element's InnerText until a match is found and then fill in the next input field you come to (usually works).
    - The Returned Values of the GetAttribute method must be ANY variables , even though they return STRINGS