Link to home
Start Free TrialLog in
Avatar of rshaham
rshaham

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rshaham
rshaham

ASKER

thank you It works perfectly
You're welcome! Thanks for the points!