I use WebBrowser as program, the purpose is to automatically obtain the button, click automatically, of course, I am the first set to modify the knob title as an experiment, can realize this click is achieved, but the problem is can't find my order button, the following code
Private Sub Timer1_Timer ()
Dim i&
"' Dim IDoc As HTMLDocument
Set the IDoc=WebBrowser1. Document
"' Dim Acollection As IHTMLElementCollection
' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
' ' ' ' ' ' ' 'the original code
The Set Acollection=IDoc. All. Tags (" button ")
Dim s2 As String
For I=0 To Acollection. Length - 1
S2=Acollection. Item (I). Type the
The Debug. Print s2
If s2="button" Then Acollection. Item (I). The Value="https://bbs.csdn.net/topics/222", "this is to let me see
If Acollection. Item (I). The Name="word" is Then Acollection. Item (I). The Value="HTTP://https://bbs.csdn.net/topics/this is what I want to find"
Next
' ' ' ' ' ' ' ' ' ' ' 'to modify test' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
The 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 the
S33=Acollection. Item (I). The Name
'the Debug. Print s3
If the s3="button" Then Acollection. Item (I). The Value="hello" https://bbs.csdn.net/topics/'here as a result of the display
If s33="btnModify" Then
Acollection. Item (I). The Value="https://bbs.csdn.net/topics/" I want to find the
End the If
End the If
' ' ' ' ' 'If s33="btnModify" Then Acollection. The Item (I). Click
Next
Test results are all buttons are found, which is all button shows "2222222" or "hello"
But couldn't find my refers to words that modify & lt; Button>
Solution of how to solve
CodePudding user response:
Why don't you use ID to check? The WEBBROWSER. DOCUMENT. GETELEMENTBYID. The btnModify so not check? Finished directly CLICK event, he in the implementation of the WEBBROWSER. DOCUMENT. GETELEMENTBYID. BtnModify. CLICK ();CodePudding user response:
For Sub and modify button and click ()
On the Error Resume Next
With CreateObject (" internetexplorer. Application ")
The Visible=True
. Navigate "http://www.abcd1234.com/" fill in the web address here
Do Until the ReadyState=4
DoEvents
Loop
. Document. All (" btnModify "). The Value="https://bbs.csdn.net/topics/1234567890" tag, main is to see whether the modify button
. Document. All (" btnModify "). Click, Click '
End With
End Sub
CodePudding user response:
Your HTM label has a name attribute. You can only through the s33=Acollection Item (I). The name get relative value, if have no you, of course, is less than the name, the value of this attribute, and, at the front desk in the script usually in the id attribute to use object, name attribute is usually the form will only be used when data is submitted to the server scripts, so you changed to s33=Acollection. Item (I). The id may workCodePudding user response:
The solution? Met the same problem, ha haCodePudding user response:
Solve:
'test button click event bindings page
Dim doc As HtmlDocument=webMain. Document
Dim btnTest As HtmlElement=doc. All (" btnTest ")
'entrust processing event handler
If Not IsNothing (btnTest) Then
AddHandler btnTest. Click AddressOf btnTest_Click
End the If
Private Sub btnTest_Click (ByVal sender As Object, ByVal e As HtmlElementEventArgs)
Dim obj As HtmlElement=CType (sender, HtmlElement)
The Debug. Print (" receive "& amp; Obj. Id & amp; "" & amp; E.E ventType & amp; "Event")
End Sub
CodePudding user response:
I resolved to figure out why, the problem is that this web page in the box. I want to consult the 2nd floor, and upstairs, my original code with you what this code is different, which one better