|
-
May 5th, 2010, 07:10 PM
#1
Thread Starter
Frenzied Member
Problem Programatically clicking links in WebBrowser control
Hi all i have html page loaded in to my webbrowser controle that looks like this:
<a href="http://www.somesite.com/recordds.wmt?page=31" title="Go to Next Page" onfocus="if(this.blur)this.blur();"
> next »</a>
I used the following code to click on it but it doesn't work . could you guys tell me what i am doing wrong ? Thanks
Code:
Private Sub Command8_Click()
For Each ele In WebBrowser1.Document.getelementsbytagname("a")
If ele.innertext = " next »" Then ele.Click
Next
End Sub
or
Code:
Private Sub Command8_Click()
For Each ele In WebBrowser1.Document.getelementsbytagname("a")
If ele.innertext = "next" Then ele.Click
Next
End Sub
-
May 6th, 2010, 04:01 AM
#2
Re: Problem Programatically clicking links in WebBrowser control
try
if instr(ele.innertext, "next") > 0 then ele.click
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
May 6th, 2010, 10:18 PM
#3
Thread Starter
Frenzied Member
Re: Problem Programatically clicking links in WebBrowser control
 Originally Posted by westconn1
try
if instr(ele.innertext, "next") > 0 then ele.click
Many thanks it worked well. Is there away that wait untill the next button load the page in webbrowser then do other things ? I tried this but it never loades the new next page only it loads whatever the page was in text1.text at start over and over . only at the end the next page get clicked once but even then text1 doesn't show the last new url!
could you help me fix this problem.Thanks
Code:
Private Sub Command9_Click()
For i = 0 To 4
TxtHTML = ""
RichTextBox1 = ""
WebBrowser1.Navigate Text1.Text
TxtHTML = Inet1.OpenURL(Text1.Text)
Label2.Caption = "Current Item:" & i
Do Until WebBrowser1.ReadyState = 4
DoEvents
Loop
Text1.Text = ""
Command2_Click ' chap html
Command3_Click 'get items
For Each ele In WebBrowser1.Document.getelementsbytagname("a")
'If ele.innertext = "Go to Next Page" Then ele.Click
If InStr(ele.innertext, "next") > 0 Then ele.Click
Next
'wait for webbrowser to load then go next
Do Until WebBrowser1.ReadyState = 4
DoEvents
Loop
Text1.Text = WebBrowser1.LocationURL
Next i
MsgBox "Complete"
End Sub
Last edited by tony007; May 6th, 2010 at 10:46 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|