Question webbrowser, click webpage button?

assafey

Member
Joined
Apr 13, 2009
Messages
10
Programming Experience
1-3
Hi,

I have an HTML text:

HTML:
<input type="hidden" name="dl.start" value="Free" />

                        <img src="/img2/dl_langsam.gif">

                        <br />

                        <input type="submit" value="Free user" />                        

                    </form>




How can I click on this button called "Free User" with a vb. net code?



I tried to use the code bellow, but how can I get all the element IDs of the webbrowser and know which one belongs to Free User button?



VB.NET:
WebBrowser1.Document.GetElementById(???).InvokeMember("Free User")



Thanks!
 
Last edited:
Use the GetElementsByTagName method to get the input elements, look into each using the GetAttribute method to determine that you have the right element, then you invoke the "click" member.
 
Hi,

Thank you for your reply!

I tried to do this (bellow) but didn't get the any TagName ....

VB.NET:
For Each i As HtmlElement In WebBrowser1.Document.links
Me.ListBox1.Items.Add(i.GetElementsByTagName("input"))
Next
or

VB.NET:
For Each i As HtmlElement In WebBrowser1.Document.links
if i.name = "dl.start" then
     Me.ListBox1.Items.Add(i.TagName)
end if
Next

Can you be more specific?
 
What has "links" got to do do with anything? Use GetElementsByTagName method for the element you want to query, for example the browser Document. GetElementsByTagName returns a HtmlElementCollection, which you can iterate with a loop, each element in the collection is a HtmlElement.
 
Thanks,

But, I just don't get it, sorry. Can you give me an example of a code that can

get me the TagName of a WebBrowser button?

I can't found a similar code in the net.:(
 
Hi,

I think I am starting to get the element idea. But, I tried the next code and nothing happands. No button was clicked. Why?



VB.NET:
For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
            Dim type As String = element.GetAttribute("type")
            If type = "submit" Then
                Me.ListBox1.Items.Add("Found")
                element.InvokeMember("Free user")
                Exit For
            End If
        Next


The first "submit" type has a "Free user" value in the HTML doc.
 
JohnH said:
then you invoke the "click" member
assafey said:
element.InvokeMember("Free user")
No HtmlElements has a "Free user" method, to make it "click" you have to invoke the "click" method as I said.
 
Excellent, I think you can edit first post in thread and change thread prefix to "answered" or something.
 
Back
Top