How To Click A Button On A Web Page From VB

I wont to use this site: (Image with translation attach)
i know how fill the fields "city name" and last name but the code I'm using to find out the search button "Press_Buttun(486 - .WebBrowser1.Location.X, 678 - .WebBrowser1.Location.Y)"
works only if supply 486 and 678 that means the form when web-browser In must be in Only one size and the same with web-Browser control

I found this code but it don't  don't work at all:
        Dim theElementCollection As System.Windows.Forms.HtmlElementCollection = frmMain.WebBrowser1.Document.GetElementsByTagName("input")
        For Each curElement As Windows.Forms.HtmlElement In theElementCollection
            If curElement.GetAttribute("name").Equals("ctl00$SPWebPartManager1$g_188bf43d_b2b0_41b1_8939_2a473c339706$ctl02$m_lnk_Search") Then
                Exit For
            End If

this is the problem: 
i must run this sub with fix coordinate(486,678)
Press_Buttun(486 - .WebBrowser1.Location.X, 678 - .WebBrowser1.Location.Y)

this is the function itself:
Private Sub Press_Buttun(ByVal x1 As Integer, ByVal y1 As Integer)
        Dim handle As IntPtr = search_for_handle(frmMain.Handle, "Internet Explorer_Server")
        Dim lParam As IntPtr = ((y1 << 16)) + x1 ' The coordinates
        Dim wParam As IntPtr = IntPtr.Zero ' Additional parameters for the click (e.g. Ctrl)
        Dim downCode As UInteger = 513 'Left click down code
        Dim upCode As UInteger = 514 'Left click up code
        SendMessage(handle, downCode, wParam, lParam) ' Mouse button down
        SendMessage(handle, upCode, wParam, lParam)
    End Sub

Open in new window

Who is Participating?
Check this :
or this :

Else the onclick attribute is set with :
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$SPWebPartManager1$g_188bf43d_b2b0_41b1_8939_2a473c339706$ctl02$m_lnk_Search", "", true, "", "", false, false))

Open in new window

Try to call it directly :
Private Sub Press_Buttun() {
   WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$SPWebPartManager1$g_188bf43d_b2b0_41b1_8939_2a473c339706$ctl02$m_lnk_Search", "", true, "", "", false, false));

Open in new window

rshahamAuthor Commented:
thank you It works perfectly
You're welcome! Thanks for the points!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.