[HELP] Hi - Bot help

Posts 1–15 of 18 · Page 1 of 2
[HELP] Hi - Bot help
HI,
Well, I'm making a bot for a browser game and I'm trying to shorten my code...
FOr example, I don't know why, I have to put this code in two seperated subs:

Code:
Public Sub LogIn()
    Dim threadFreeze As System.Threading.Thread
    Dim WithEvents threadFreezeMe As cFreezeME        
WebBrowser1.Document.GetElementById("user").SetAttribute("value", "lala")
        WebBrowser1.Document.GetElementById("password").SetAttribute("value", "lala")
        WebBrowser1.Document.GetElementById("login_button").InvokeMember("click")
        Dim threadFreezeMe As New cFreezeME

        threadFreeze = New Threading.Thread(AddressOf threadFreezeMe.FreezeME)
        threadFreeze.Start()

                Dim elementList As HtmlElementCollection
                Dim curElement As HtmlElement
                elementList = WebBrowser1.Document.GetElementsByTagName("a")
                For Each curElement In elementList
        
        
                If curElement.GetAttribute("innerText").Equals("Mundo 20") Then
        
                curElement.InvokeMember("click")
        
               Next


    End Sub
Can anyone tell me whats wrong? I have to put the part before the "sleep" in one sub, and them acctivate the other with a timer(ofc that I take the "sleep" when I use the timer)... the webpage needs some time to load the litlle window for me to sellect the world(thats why I need to wait/use timers)... Any ideas?


PS: this is the other Class (for the multithreding). Its pretty much the same as one that I saw in this forums (only some minor changes):


Code:
    Public Class cFreezeME
        Public Function FreezeME()
            Threading.Thread.Sleep(5000)
            Return MsgBox("Login done!")
        End Function
    End Class

EDIT: I forgot to say that the sleep part works, cause it pops ups a message box, but it doesn't click the button for some reason... (Button inner Text is "Mundo 20")
A. Why would you have to put it into two separate subs.
Create a function out of it, and call it when you want (or just call the sub)

[highlight=vbnet]
Public Sub LogIn()
Dim threadFreeze As System.Threading.Thread
Dim WithEvents threadFreezeMe As cFreezeME
WebBrowser1.Document.GetElementById("user").SetAtt ribute("value", "lala")
WebBrowser1.Document.GetElementById("password").Se tAttribute("value", "lala")
WebBrowser1.Document.GetElementById("login_button" ).InvokeMember("click")
Dim threadFreezeMe As New cFreezeME

threadFreeze = New Threading.Thread(AddressOf threadFreezeMe.FreezeME)
threadFreeze.Start()

Dim elementList As HtmlElementCollection
Dim curElement As HtmlElement
elementList = WebBrowser1.Document.GetElementsByTagName("a")
For Each curElement In elementList


If curElement.GetAttribute("innerText").Equals("Mundo 20") Then

curElement.InvokeMember("click")

Next


End Sub
[/highlight]

Just fire LogIn() when you want to....

Next thing, in stead of using html collections, try this to click the submit button.

[highlight=vbnet]
WebBrowser1.Document.Form(0).submit
[/highlight]

or

[highlight=vbnet]
WebBrowser1.Document.Form(1).submit
[/highlight]

instead of

[highlight=vbnet]
Dim elementList As HtmlElementCollection
Dim curElement As HtmlElement
elementList = WebBrowser1.Document.GetElementsByTagName("a")
For Each curElement In elementList


If curElement.GetAttribute("innerText").Equals("Mundo 20") Then

curElement.InvokeMember("click")

Next
[/highlight]



Depending on which web form it is on.



Next, why are you sleeping the thread? if it is to make sure the page is loaded, use Document Complete.
Quote Originally Posted by NextGen1
A. Why would you have to put it into two separate subs.
Create a function out of it, and call it when you want (or just call the sub)
Well, I do have a sub... (that one) but when I call it (on button_press) it doens't work with only that sub... I have to split it in two subs (with a timer to wait...) for some reason.... I'll try to use some different code, make a new project cause this one is messy.... I'll edit this post in 5/10 min with the new code to see if it works....
The reason for that is most likely because the website hasn't loaded and therefor cannot find the elementID you are trying to click.

instead, Check to see if the webbrowser has finished loading the page, then check the title of the page, if it is completed and has a certain title, then trigger the action

So

[highlight=vbnet]
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEv entArgs) Handles WebBrowser1.DocumentCompleted
If WebBrowser1.DocumentTitle = "Google" Then ' You can get the Document title from the source inbetween the <title>Google</title> or from the tab or w/e
Try
Login()
Catch ex As Exception

End Try

End If
End Sub
[/highlight]

That's just an example.

This way you only need one sub, and really it should be a function,
Well, ty for the docomentcompleted tip... That made my sub to send atacks work =D

Unfortunatly my login sub is still uncomplete....

Let me explain how it works a little bit better:

1- It inputs the username
2- It inputs the password
3- It clicks the login button
4- A java box pops up for me to select my world (thats not of the bot, its the acctual game)


Now, I don't think that DocomentCompleted works with that... Does it?

What do you suggest?

Ty

PS: sry for taking so long to answer... but I was re-writing the bot, cause the code on the original project was SOOOO confusing...
Login will work the same way.

Document Completed, Same for Login title, if the title is the same, check to see if the document html contains a specific word not found on the other page, also make sure it is clicking to popup the java message box, IE, is your login working.?

Also, there is something called invoke script, which will help with calling a specific script, however again, the above should work the same way.


Why not just send me the link to the site via PM and I will take a look.
HUm... OK, I'll chack that out...
thanks...
PS: PM sent

issue was small, but this should solve it.

[highlight=vbnet]
Dim elementList As HtmlElementCollection
Dim curElement As HtmlElement
elementList = WebBrowser1.Document.GetElementsByTagName("a")
For Each curElement In elementList
If curElement.GetAttribute("innerText").Contains("ogi n") Then
curElement.InvokeMember("onclick")
End If
Next
[/highlight]



It looks like you're using Erinador's tutorial on threading? I'll have to say, that tut is super confusing for someone beginning in threading as it goes across classes and implemented a seemingly useless thread that only sleeps.

Basically, why are you even using a random thread on that sub?
I suggest using the common threads.

[highlight="VB"]Dim tLogin as new threading.thread(addressof login)
tLogin.priority = threading.thread.priority.highest 'default one is normal
tLogin.start[/highlight]

They're easier to understand and they don't require anything else.

That's how I taught Jason threads =D.
Quote Originally Posted by Blubb1337 View Post
I suggest using the common threads.

[highlight="VB"]Dim tLogin as new threading.thread(addressof login)
tLogin.priority = threading.thread.priority.highest 'default one is normal
tLogin.start[/highlight]

They're easier to understand and they don't require anything else.

That's how I taught Jason threads =D.
Accessing a web browser across threads dies. That was when I cheated with CheckForIllegalCrossThreadCalls, haven't tried it with delegates yet.
Quote Originally Posted by Jason View Post


Accessing a web browser across threads dies. That was when I cheated with CheckForIllegalCrossThreadCalls, haven't tried it with delegates yet.
Yes ofc. If a thread accesses the GUI controls an error will occur. That is why you can either set
[highlight="VB"]
Control.Checkforillegalcrossthreads = False[/highlight]

on form_load or use delegates.
Quote Originally Posted by Blubb1337 View Post
Yes ofc. If a thread accesses the GUI controls an error will occur. That is why you can either set
[highlight="VB"]
Control.Checkforillegalcrossthreads = False[/highlight]

on form_load or use delegates.
Lol Lrn2Read. I said it died when using CheckForIllegalCrossThreadCalls = False .
Quote Originally Posted by Jason View Post


Lol Lrn2Read. I said it died when using CheckForIllegalCrossThreadCalls = False .
You choob prolly used me.checkf...rather than control.checkf..!
I think he was using the thread solely to sleep the application in hopes it would load the page.

Which is why I explained about document_completed.

(not sure though)
Posts 1–15 of 18 · Page 1 of 2
This thread is closed for replies.

Tags for this Thread

None

Talk with us