Re: Click Forum Login Button
what's the HTML code for the button? also, have you made sure that the actual textboxes are getting populated fully before "clicking" the button? might need to put the "clicking" line in a timer and check to see if the textboxes contain a value before issuing the "click"
Re: Click Forum Login Button
I know everything works fine because I tried having it fill the text boxes and not click the login button and it filled them correctly. Then I add the Login code after that. On a site like yahoo it works fine. Click the button and it sends the correct info to the text boxes of the yahoo page and clicks the login button and I'm logged in. Works perfect.
I use the GetElementById method to fill the boxes based on their Id in the html code. (re: code I posted above) I use the same thing for the Login button and InvokeMember("click") to make it click the button. All the Id names are correct. Why is it not working? I heard somewhere it has to do with how smf processes the login or something. Does anybody know how this works? Please explain.
Re: Click Forum Login Button
...or don't post the source code... stop comparing it to yahoo.. it isn't yahoo.
i had to go find another smf-based forum (see previous post's first request) and nowhere in it did I find an HTML element with the ID "Login" so... that's probably your problem.
Re: Click Forum Login Button
Here is the Login code on the Login Page:
Code:
<div class="roundframe">
<dl>
<dt>Username:</dt>
<dd><input type="text" name="user" size="20" value="" class="input_text" /></dd>
<dt>Password:</dt>
<dd><input type="password" name="passwrd" value="" size="20" class="input_password" /></dd>
</dl>
<dl>
<dt>Minutes to stay logged in:</dt>
<dd><input type="text" name="cookielength" size="4" maxlength="4" value="60" class="input_text" /></dd>
<dt>Always stay logged in:</dt>
<dd><input type="checkbox" name="cookieneverexp" class="input_check" onclick="this.form.cookielength.disabled = this.checked;" /></dd>
</dl>
<p><input type="submit" value="Login" class="button_submit" /></p>
<p class="smalltext"><a href="http://mydomain.com/index.php?action=reminder">Forgot your password?</a></p>
<input type="hidden" name="hash_passwrd" value="" />
</div>
This is from an smf forum. It uses "Login" as the Id. See:
Code:
<p><input type="submit" value="Login" class="button_submit" /></p>
So wrong Id is not my problem. I used all the Ids mentioned in the above code.
Re: Click Forum Login Button
then you need an HTML lesson..
<p><input type="submit" value="Login" class="button_submit" /></p>
i don't see the word "id" in that line ANYWHERE
you're going to have to loop through the HTMLCollection of "input" elements and check the attribute "value" to see if it equals "Login", if it does, invoke the click method.
for kicks, here's the code for the yahoo login page:
HTML Code:
<div id='inputs'>
<label for='username'>Yahoo! ID</label>
<input name='login' id='username' maxlength='96' tabindex='1'>
<p id='ex'>(e.g. [email protected])</p>
<label for='passwd'>Password</label>
<input name='passwd' id='passwd' type='password' maxlength='64' tabindex='2'>
</div>
notice anything? the username and password input fields have ID's (username and 'passwd', respectively.
try this:
vb.net Code:
Dim webBrowserDocument As HtmlDocument = webBrowser.Document
Dim hec As HtmlElementCollection = webBrowserDocument.GetElementsByTagName("input")
For Each element As HtmlElement In hec
If element.GetAttribute("name") = "Login" Then
'Invoke here
End If
Next
Re: Click Forum Login Button
Ok this is starting to make sense. For the sake of simplifying things I created 2 buttons. Button1 sends the username and password to the corresponding boxes in the forum. Button2 clicks the Login button.
Button1 code:
Code:
Me.WebBrowser1.Document.GetElementById("user").SetAttribute("value", "myusername")
Me.WebBrowser1.Document.GetElementById("passwrd").SetAttribute("value", "mypassword")
Button2 code:
Code:
Dim webBrowserDocument As HtmlDocument = WebBrowser1.Document
Dim hec As HtmlElementCollection = webBrowserDocument.GetElementsByTagName("input")
For Each element As HtmlElement In hec
If element.GetAttribute("name") = "Login" Then
'InvokeMember Here???????????????
End If
Next
I'm new to VB. So, I'm a bit confused on how to use the InvokeMember in this case. It was easy in my first example with the yahoo page. But this is a little different. How would I type it out?
Re: Click Forum Login Button
element.InvokeMember("click") where it says "Invoke here"
Re: Click Forum Login Button
It didn't work. I click the button and it does nothing. Code below:
Code:
Dim webBrowserDocument As HtmlDocument = WebBrowser1.Document
Dim hec As HtmlElementCollection = webBrowserDocument.GetElementsByTagName("input")
For Each element As HtmlElement In hec
If element.GetAttribute("name") = "Login" Then
element.InvokeMember("click")
End If
Next
Re: Click Forum Login Button
what's the url of the website you're working with?
Re: Click Forum Login Button
OT
can you give source code to log in on yahoo..mesenger
Re: Click Forum Login Button
why not post the actual site you're trying to log into?
Re: Click Forum Login Button
Website is udgclan.com. But this will be the same exact for all sites using smf 2.0RC3 for their forum.
Re: Click Forum Login Button
Why not just do
Code:
WebBrowser1.document.forms(0).invokemember("submit")
Re: Click Forum Login Button
It still isn't working. I apologize if I'm a bit retarded at times. I really am new at this and I'm trying to grasp what I'm doing. Did I insert the code into the right spot? Code below:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim webBrowserDocument As HtmlDocument = WebBrowser1.Document
Dim hec As HtmlElementCollection = webBrowserDocument.GetElementsByTagName("input")
For Each element As HtmlElement In hec
If element.GetAttribute("name") = "Login" Then
WebBrowser1.Document.Forms(0).InvokeMember("button_submit")
End If
Next
End Sub
Re: Click Forum Login Button
Well, you're combining the two suggestions, which really doesn't work in this case:
either do:
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim webBrowserDocument As HtmlDocument = WebBrowser1.Document
Dim hec As HtmlElementCollection = webBrowserDocument.GetElementsByTagName("input")
For Each element As HtmlElement In hec
If element.GetAttribute("name") = "Login" Then
element.InvokeMember("click")
End If
Next
End Sub
or the other suggestion (which is a good suggestion):
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Document.Forms(0).InvokeMember("submit") 'not button_submit
End Sub
Re: Click Forum Login Button
It finally worked!!! Thank you so much!!!
The first option didn't work. It was the second option that worked for me. The below code successfully clicks the login button on an smf forum.
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Document.Forms(0).InvokeMember("submit") 'not button_submit
End Sub
Re: Click Forum Login Button
Good deal. Sometimes the Forms way (the way that worked) can be troublesome, like if you wanted to add a Poll or a contact form to the main page, it might re-order the form's place in the HTML document.
Re: Click Forum Login Button
Yes, but if that was the case you would take another route to do it.
Something like:
Code:
Dim htmEle As HtmlElement = (From elem In WebBrowser1.Document.GetElementsByTagName("input") Where elem.OuterHtml.ToLower.Contains("class=button_submit") Select elem)(0)
htmEle.InvokeMember("click")
Re: Click Forum Login Button
look at the code here " If element.GetAttribute("name") = "Login" Then"
now look closer here "GetAttribute("name")" was there a "name" in the button call " Login"? no that should be "value"
Quote:
Originally Posted by
DeepMagic22
It still isn't working. I apologize if I'm a bit retarded at times. I really am new at this and I'm trying to grasp what I'm doing. Did I insert the code into the right spot? Code below:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim webBrowserDocument As HtmlDocument = WebBrowser1.Document
Dim hec As HtmlElementCollection = webBrowserDocument.GetElementsByTagName("input")
For Each element As HtmlElement In hec
If element.GetAttribute("name") = "Login" Then
WebBrowser1.Document.Forms(0).InvokeMember("button_submit")
End If
Next
End Sub
Should look like this
Code:
Dim webBrowserDocument As HtmlDocument = WebBrowser1.Document
Dim hec As HtmlElementCollection = webBrowserDocument.GetElementsByTagName("input")
For Each element As HtmlElement In hec
If element.GetAttribute("value") = "Login" Then
element.InvokeMember("click")
End If
Next