Question How to open Webbrowser, click on form and skip to the next webpage from a listbox?

FrankyBkk

New member
Joined
Dec 25, 2013
Messages
1
Programming Experience
10+
Hello to everybody,

I am searching since days for a solution to stabilize my handling of a webpage that I control with vb studio 2012.

It is a program to send bulk message in a existing webpage to all the users. (Just to mention it: I have friendly intentions and it is my own Webpage!)

+ + + + + + + + + +

Explanation:

I created a Form1 in which are the data where to go (URL) etc.

Form2 is my webbrowser object, nothing else

Form3 call Form2 to open a dating webpage.

+ + + + + + + + + +

In Form 3 ...

I read all the users in a listbox. Then I open the user profiles (http://datingwebpage/username1) and then (http://datingwebpage/username2) and so on to the end of the Listbox.

For every user profile the "For each" jumps to "Private Sub" and have to click the button "New Message" which opens another webpage with a form.

Then I paste from my Form1 the "Form1.rtfMessage" in the body of this form

After it, I click the "submit" button .

Then I move to the next user in the listbox and start the same procedure ... and son on and on.

+ + +

I get this not running, only when I do it with delays by included between the steps a message box.

I was trying to understand the Await / Backgroundworker / Try and all this things, but I got nothing really to handle the time for this actions.

How to stabilize my code?

Here is the code of the critical area of the program:

Private Sub btnSendMessages_Click(sender As Object, e As EventArgs) Handles btnSendMessages.Click

'strWebsiteCountry is a public variable (de, ch, at) for the country
'strWebsiteURL is a public variable ("www.dating.")

Dim strWebsite
strWebsite = strWebsiteURL & strWebsiteCountry & "/"

If lboxUser.Items.Count = 0 Then
MsgBox("Listbox is empty")
Exit Sub
End If

Dim i As Integer
Dim strWebsitename As String

For i = 0 To lboxUser.Items.Count - 1

If lboxUser.Items(i).ToString <> "FrankyBkk" Then

lboxUser.Items(i).ToString()

strWebsitename = strWebsite & lboxUser.Items(i).ToString
WebBrowser1.Navigate(strWebsitename)

'Execute all the following Subs and wait from Sub to Sub until they are finished

MessageButtonClick()

MessagePaste()

MessageSubmit()

End If

Next

End Sub

'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Private Sub MessageButtonClick()

Dim links As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("A")

For Each link As HtmlElement In links

If link.InnerText = "New Message" Then
link.InvokeMember("Click")
End If

Next

End Sub

Private Sub MessagePaste()

WebBrowser1.Document.GetElementsByTagName("textarea").Cast(Of HtmlElement).ToArray.Where(Function(elem) elem.Name = "body").First.InnerHtml = Form1.rtfMessage.Text

End Sub

Private Sub MessageSubmit()

WebBrowser1.Document.Forms(0).InvokeMember("Submit")

End Sub

I did not include in this sample code any waiting handling because whatever I tried did anyway not work.

I would be very happy if somebody can show me how to make this code web safe!!!

I don't get the code to jump to the next User. I don't get the code to execute the "submit" button, I don't get the code to paste the text ... only when I include between the steps msgboxes, otherwise the code stops after showing the User 1 Profile.

Thank you in advance!

Frank
 
Last edited:

Latest posts

Back
Top