Thread: FoxPro Some General Questions/Internet Explorer Automation

Internet Explorer Automation
By Rick Strahl

cValue = "JA0000165801"
oIE = CREATEOBJECT("InternetExplorer.Application")
oIE.Navigate("http://www.fastway.com.au")
IF WaitForReadyState(oIE)
        oIE.Document.FTrace.TAG.value = ALLTRIM(cValue)
        oIE.Document.FTrace.Submit()
        oIE.Visible = .t.
ELSE
        MESSAGEBOX("Internet Connection timed out",64,"Apparently no Internet Connection")
ENDIF

oIE = null

--------------------

FUNCTION PageCatalog
   LPARA oIE
   CREATE CURSOR PageCatalog (ItemIndex i, InnerText M, InnerHTML M)
   FOR i = 0 TO oIE.Document.Body.All.Length - 1
      m.ItemIndex = i
      m.InnerText = oIE.Document.Body.All(i).InnerText
      m.InnerHTML = oIE.Document.Body.All(i).InnerHTML
      INSERT INTO PageCatalog FROM MEMVAR
   ENDFOR
ENDFUNC


-----------------------

document.forms[x][y]
is a multi-dimesioned array where 0->x is all the forms on a page, and 0->y is all the fields in the form.
So,
document.forms[1][2].name
is the name of the 3rd field on the second form of the page.

Googled 'looping web page form javascript' to get the answer.



Browser Control - How to submit : original

* Create test htm
Text to m.Test noshow


EndText
StrToFile(m.test,'testme.htm')

oForm = Createobject('form1',Sys(5)+Curdir()+'testme.htm')
oForm.Show()
Read Events

Define Class form1 As Form
  Top = 0
  Left = 0
  Height = 470
  Width = 740
  DoCreate = .T.
  Caption = "HTML sample"
  Name = "Form1"
  cHTML = ""
  FirstTime = .t.

  * This is IE control - you'd use webbrowser4 from gallery instead
  * just because it already has some checks, extra pem. ie: wouldn't need readystate part
  * for the sake of keeping code short here I directly use olecontrol itself
  Add Object htmlviewer As OleControl With ;
    Top = 12, ;
    Left = 12, ;
    Height = 396, ;
    Width = 708, ;
    Visible = .T., ;
    Name = "HTMLViewer", ;
    OleClass = 'Shell.Explorer'

  Procedure Init
  Lparameters tcHTML
  With Thisform.htmlviewer
    .Navigate2(m.tcHTML)
    Do While .ReadyState # 4 && Wait for ready state
    Enddo
  Endwith
Endproc

  Procedure htmlviewer.NavigateError
  Lparameters pdisp, url, frame, statuscode, Cancel
  Cancel = .T.
Endproc

  Procedure htmlviewer.BeforeNavigate2
  Lparameters pdisp, url, flags, targetframename, postdata, headers, Cancel
  lcVals = ""
  If This.Object.Document.Forms.Length > 0
    For Each oFrm In This.Object.Document.Forms
      lcVals = lcVals + oFrm.Name + Chr(13)
      If oFrm.elements.Length > 0
        For Each oElem In oFrm.elements
          If oElem.Type = "select-multiple"
            lcList=''
            For ix=0 To oElem.Length-1
              If oElem.Item(ix).Selected
                lcList = lcList + Iif(Empty(lcList),'',',')+oElem.Item(ix).Value
              Endif
            Endfor
            lcVals = lcVals + "Name :" + oElem.Name + "/Value:"+lcList + Chr(13)
          Else
            lcVals = lcVals + "Name :" + oElem.Name + "/Value:"+oElem.Value + Chr(13)
          Endif
          oElem = .Null.
        Endfor
      Endif
      oFrm = .Null.
    Endfor
  Endif
  Cancel = !thisform.FirstTime  && prevents actual navigation
  thisform.FirstTime = .F.
  Messagebox(lcVals)
Endproc

  Procedure htmlviewer.Refresh
  Nodefault
Endproc

  Procedure QueryUnload
  Clear Events
Endproc
Enddefine



Again submission from FoxPro:

oIE = CREATEOBJECT("InternetExplorer.Application")
oIE.Navigate("fox.wikis.com/wc.dll?wiki~Find")
INKEY(1)
nStartSeconds = SECONDS()
* bug fixed by Erik Moore Nov 25/99
DO WHILE oIE.ReadyState <> 4 AND (SECONDS()-nStartSeconds < 30)
ENDDO
oie.document.forms(0).TopicSearch.Value = alltrim(this.parent.txtWikiTerm.value)
oIE.Document.Forms(0).Submit()
oIE.Visible = .T.



By Juri Shutenko:

oIE.Navigate("http://kbo-bce-ps.mineco.fgov.be/ps/kbo_ps/kbo_search.jsp?lang=nl&dest=SON")
oDoc=oIE.document
oIE.Visible=.T.
oDoc.forms.item(1).item(0).value="0427"
oDoc.forms.item(1).item(1).value="807"
oDoc.forms.item(1).item(2).value="711"
oDoc.forms.item(1).item(3).Click()

Original