How To Click A Button On A Web Page From VB

I wont to use this site: http://www.cellcom.co.il/support/info/phonebbok/pages/default.aspx (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
                curElement.InvokeMember("onclick")
                Exit For
            End If
        Next

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)
        DoEvents()
    End Sub

Open in new window

Question.GIF
Sample-Project.zip
rshahamAsked:
Who is Participating?
 
leakim971PluritechnicianCommented:
Check this : http://wiki.asp.net/page.aspx/1082/dopostback-function/
or this : http://www.xefteri.com/articles/show.cfm?id=18

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

0
 
rshahamAuthor Commented:
thank you It works perfectly
0
 
leakim971PluritechnicianCommented:
You're welcome! Thanks for the points!
0
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.