注册 登录
编程论坛 VB.NET论坛

vb.net怎么单击webbrowser中iframe中的按钮

zsdqxzxx 发布于 2016-12-23 11:03, 2953 次点击
必须引用Microsoft html object library
这是以前VB的方法,不知道怎么用啊。
单击command1获得框架及其元素方法1
Private Sub Command1_Click()
Dim Doc2 As HTMLDocument
Dim Web2 As WebBrowser_V1
 Set Web2 = GetFrameIframeLikeUrl(WebBrowser1.Document, "*baidu.com*")
If Not Web2 Is Nothing Then
    Set Doc2 = Web2.Document
   Doc2.getElementById("JZGXXJLXX_addBtn").Click,单击了网页框架中的按钮
End If
End Sub


Function GetFrameIframeLikeUrl(Vdoc As HTMLDocument, LikeUrl As String) As WebBrowser_V1

Dim Vtag, Tname As String, FrameWeb As WebBrowser_V1
For Each Vtag In Vdoc.All
        Tname = Vtag.tagName
        If Tname = "IFRAME" Or Tname = "FRAME" Then
            Set FrameWeb = Vtag
              If FrameWeb.LocationURL Like LikeUrl Then
 
                  Set GetFrameIframeLikeUrl = FrameWeb
                  Exit Function
             End If
        End If
Next
End Function


不知在中怎么实现。

[此贴子已经被作者于2016-12-23 11:04编辑过]

3 回复
#2
zs李四2017-01-24 10:13
如果你找到的按钮(bb)是正确的,用下面语句:
bb.InvokeMember("click")
为了回到你问题,专门注册到这个论坛^_^,因为我也曾经在网络上获得过别人的帮助。
#3
zsdqxzxx2017-01-30 11:35
谢谢
#4
com343142017-05-23 21:02
单击command1获得框架及其元素方法1
 Private Sub Command1_Click()
 Dim Doc2 As HTMLDocument
 Dim Web2 As WebBrowser_V1
  Set Web2 = GetFrameIframeLikeUrl(WebBrowser1.Document, "*baidu.com*")
 If Not Web2 Is Nothing Then
     Set Doc2 = Web2.Document
   Doc2.getElementById("JZGXXJLXX_addBtn").Click,单击了网页框架中的按钮
End If
 End Sub


 Function GetFrameIframeLikeUrl(Vdoc As HTMLDocument, LikeUrl As String) As WebBrowser_V1

 Dim Vtag, Tname As String, FrameWeb As WebBrowser_V1
 For Each Vtag In Vdoc.All
         Tname = Vtag.tagName
         If Tname = "IFRAME" Or Tname = "FRAME" Then
             Set FrameWeb = www.
               If FrameWeb.LocationURL Like LikeUrl Then
  
                   Set GetFrameIframeLikeUrl = FrameWeb
                   Exit Function
              End If
         End If
 Next
 End Function
1