Excel控制IE

---恢复内容开始---

1、初始化and连接http网页

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate "http://10.251.68.38:8088/....."
Do Until ie.Readystate = 4
    DoEvents
Loop

2、索引对象

  1.by id/name(getElementById搜索时包揽id、name)
ie.Document.getElementById("name").Value = "aaa"
   2.by tagName
For i = 0 To ie.Document.All.Length - 1
    If UCase(ie.Document.All(i).tagName) = "INPUT" Then
        If UCase(ie.Document.All(i).Type) = "IMAGE" Then
            ie.Document.All(i).Click
            Exit For
        End If
    End If
Next
  3.访问frame内元素
For k = 0 To ie.Document.frames.Length - 1
    For i = 0 To ie.Document.frames(k).Document.All.Length - 1
        If UCase(ie.Document.frames(k).Document.All(i).tagName) = "A" Then
            ss = ie.Document.frames(k).Document.All(i).href
            If InStr(1, ss, "menuID=201", vbTextCompare) > 0 Then
'            If ie.Document.frames(k).Document.All(i).href = "../inventory/searchInv.jsp?menuID=201" Then
                ie.Document.frames(k).Document.All(i).Click
                Exit For
            End If
        End If
    Next
Next

3、读取、修改元素属性

 元素各个属性能直接访问,如

ie.Document.All(“name”).Value

ie.Document.All(i).scr

ie.Document.All(i).href

 

posted @ 2016-07-08 16:17  lulu47  阅读(278)  评论(0编辑  收藏  举报