webbrowser help need..newbie...button click

sourind

New member
Joined
Apr 5, 2006
Messages
4
Programming Experience
1-3
suppose...i have a webbrowser control on a form.....
and one button..

i go to www.google.com..
then
first i put some text in search box...now i want to click the "Search" button by clicking the button(on my form)..i use the following code...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Document.Forms(0).InvokeMember("SUBMIT")
End Sub
...................

now instead of "Search" button, suppose i want to click the "I m feeling lucky "button...
what would be the code then??
thanking in advance...


 
This worked from the Html source displayed when www.google.com was loaded, could change or be different for languages, anyway 'q' was the name of the text input and Value attribute is set to the search string, 'btnI' was the name of the 'Lucky' button and Click method is invoked.
VB.NET:
[SIZE=2]WebBrowser1.Document.All.GetElementsByName([/SIZE][SIZE=2][COLOR=#800000]"q"[/COLOR][/SIZE][SIZE=2])(0).SetAttribute([/SIZE][SIZE=2][COLOR=#800000]"Value"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"VB.Net Forums"[/COLOR][/SIZE][SIZE=2])
WebBrowser1.Document.All.GetElementsByName([/SIZE][SIZE=2][COLOR=#800000]"btnI"[/COLOR][/SIZE][SIZE=2])(0).InvokeMember([/SIZE][SIZE=2][COLOR=#800000]"Click"[/COLOR][/SIZE][SIZE=2])
[/SIZE]

 
Back
Top