在一网页内,相关代码如下
<div id="toolbar" style="margin-top: 3px;">
<button type="button" id="btnClose" name="btnClose">
退出</button>
<button type="button" id="btnSave" name="btnSave">
保存</button>
<button type="button" id="btnModify" name="btnModify">
修改</button>
<button type="button" id="btnSCustomer" name="btnClose">
转我客户</button>
<button type="button" id="btnPrivateCustomer" name="btnClose">
转公共</button>
<button type="button" id="btnReturn" name="btnReturn">
退回</button>
</div>
我用WebBrowser作程序,目的 是将自动获取按扭,自动点击,当然,我是先设为修改安钮标题作为试验,能实现这个点击也就实现了,但问题是找不到我批定按钮。代码如下
Private Sub Timer1_Timer() Dim i&
'' Dim IDoc As HTMLDocument
Set IDoc = WebBrowser1.document
''' Dim Acollection As IHTMLElementCollection
'' '' '' '' '' ' '' '' '' '' ''
''''''''原来代码 Set Acollection = IDoc.All.tags("button")
Dim s2 As String
For i = 0 To Acollection.length - 1
s2 = Acollection.Item(i).Type
Debug.Print s2If s2 = "button" Then Acollection.Item(i).Value = "222" ’这是为让我看到效果
If Acollection.Item(i).Name = "word" Then Acollection.Item(i).Value = “这就是我要找的” Next' '' '' '' '' '' '修改测试'' '' '' '' '' '' '' '' '' '' '' '' '' '' ''‘’‘’‘’‘’‘’‘’‘’‘’‘’‘ '' '' '' '' '' '' '' '' ''
Set Acollection = IDoc.All.tags("button")
Dim s3 As String
Dim s33 As String
For i = 0 To Acollection.length - 1
s3 = Acollection.Item(i).Type
s33 = Acollection.Item(i).Name
' Debug.Print s3
If s3 = "button" Then Acollection.Item(i).Value = "你好呀" ‘这里结果显示出来了
If s33 = "btnModify" Then
Acollection.Item(i).Value = "我要找的"
End If
End If
'''''' If s33 = "btnModify" Then Acollection.Item(i).Click
Next测试结果是所有按钮都找到了,也就是 所有按钮 都显示“2222222” 或"你好呀"
但就是找不到我指字的那个 修改<button>
求解如何解决
<div id="toolbar" style="margin-top: 3px;">
<button type="button" id="btnClose" name="btnClose">
退出</button>
<button type="button" id="btnSave" name="btnSave">
保存</button>
<button type="button" id="btnModify" name="btnModify">
修改</button>
<button type="button" id="btnSCustomer" name="btnClose">
转我客户</button>
<button type="button" id="btnPrivateCustomer" name="btnClose">
转公共</button>
<button type="button" id="btnReturn" name="btnReturn">
退回</button>
</div>
我用WebBrowser作程序,目的 是将自动获取按扭,自动点击,当然,我是先设为修改安钮标题作为试验,能实现这个点击也就实现了,但问题是找不到我批定按钮。代码如下
Private Sub Timer1_Timer() Dim i&
'' Dim IDoc As HTMLDocument
Set IDoc = WebBrowser1.document
''' Dim Acollection As IHTMLElementCollection
'' '' '' '' '' ' '' '' '' '' ''
''''''''原来代码 Set Acollection = IDoc.All.tags("button")
Dim s2 As String
For i = 0 To Acollection.length - 1
s2 = Acollection.Item(i).Type
Debug.Print s2If s2 = "button" Then Acollection.Item(i).Value = "222" ’这是为让我看到效果
If Acollection.Item(i).Name = "word" Then Acollection.Item(i).Value = “这就是我要找的” Next' '' '' '' '' '' '修改测试'' '' '' '' '' '' '' '' '' '' '' '' '' '' ''‘’‘’‘’‘’‘’‘’‘’‘’‘’‘ '' '' '' '' '' '' '' '' ''
Set Acollection = IDoc.All.tags("button")
Dim s3 As String
Dim s33 As String
For i = 0 To Acollection.length - 1
s3 = Acollection.Item(i).Type
s33 = Acollection.Item(i).Name
' Debug.Print s3
If s3 = "button" Then Acollection.Item(i).Value = "你好呀" ‘这里结果显示出来了
If s33 = "btnModify" Then
Acollection.Item(i).Value = "我要找的"
End If
End If
'''''' If s33 = "btnModify" Then Acollection.Item(i).Click
Next测试结果是所有按钮都找到了,也就是 所有按钮 都显示“2222222” 或"你好呀"
但就是找不到我指字的那个 修改<button>
求解如何解决
解决方案 »
- cast(int as binary(3))转换出来的结果无法显示,怎么办,高分求救!(50)
- 超级郁闷,进来帮忙!VB
- 程序主窗体关闭后,如何关闭所有打开的窗体
- ASP实现文件内容的识别???
- 高手请进!!高分求救!!小弟急需
- 求救:DataReport显示报表提示报表宽度超过纸张宽度!
- 软件加密,想实现这种加密功能,一般怎么做?
- 请帮我看看着段代码问题出在那里
- 窗口视口的问题,不止这50份啊!
- 求助!请问如何让一个应用程序获得焦点 100分(给个例子)
- 【临近期末 VB紧急求助!!!!!!!!】
- 请各位大侠帮忙看看使用VB脚本群发邮件时,一直提示: 运行时错误:-2147220978(8004020e)。
On Error Resume Next
With CreateObject("internetexplorer.application")
.Visible = True
.Navigate "http://www.abcd1234.com/" '这里填入网页地址
Do Until .ReadyState = 4
DoEvents
Loop
.document.All("btnModify").Value = "1234567890" '标记一下,主要是看看是不是修改按钮
.document.All("btnModify").Click '点击,
End With
End Sub
Dim doc As HtmlDocument = webMain.Document
Dim btnTest As HtmlElement = doc.All("btnTest")
'委托处理事件的处理程序
If Not IsNothing(btnTest) Then
AddHandler btnTest.Click, AddressOf btnTest_Click
End If Private Sub btnTest_Click(ByVal sender As Object, ByVal e As HtmlElementEventArgs)
Dim obj As HtmlElement = CType(sender, HtmlElement)
Debug.Print("接收到 " & obj.Id & " 的 " & e.EventType & " 事件")
End Sub