Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27349

VS 2008 Problem with webbrowser control

$
0
0
Hi folks!

I need some help with one simple code snipet.
Goal is to make simple query on a site, site has one input field and one button.

I am not a coder, so please dont judge me for code format, i play around with programming languages for hobby :)

I am not actually sure if problem is in code itself, or site countemeasures for robots.


Ok here is a piece of code that i put together:

Code:

Public Class Form1
    Declare Sub Sleep Lib "kernel32" (ByVal milliseconds As Long)
    Dim newSearch As Boolean = True
    Public Declare Auto Function SetCursorPos Lib "User32.dll" (ByVal X As Integer, ByVal Y As Integer) As Long
    Public Declare Auto Function GetCursorPos Lib "User32.dll" (ByRef lpPoint As Point) As Long
    Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
    Public Const MOUSEEVENTF_LEFTDOWN = &H2 ' left button down
    Public Const MOUSEEVENTF_LEFTUP = &H4 ' left button up


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Navigate("https://vs.lkf.ee/pls/xlk/!sysadm.ic_vehicle_history_pkt.show_form")
        newSearch = True
    End Sub


    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        If newSearch = True Then 'If not new search,it doen't need repeatly execute the WebBrowser1_DocumentCompleted event 
            SendKeys.Send("{Tab}") 'Move focus to input field 
            SendKeys.Send("{Tab}")
            SendKeys.Send("{Tab}")
            SendKeys.Send("{Tab}")
            SendKeys.Send("{Tab}")
            SendKeys.Send("{Tab}")
            SendKeys.Send("{Tab}")
            SendKeys.Send("JMBSREA2AWZ001098") 'write query to input field
            ' SOME METHOD HERE TO SUBMIT QUERY
            newSearch = False
        End If
    End Sub


End Class

So problem is that when i try to make a query it displays me a captcha, but when you go to site directy with any browser, then its straight forward: fill form - submit and voila results, no captcha.

Code works well for finding input field and filling it, problem is when i try to submit it.

First i tried:

Code:

SendKeys.Send("{ENTER}")
Result: Focuses field, fills it, focuses button, submits it. I get captcha not results.

Then i tried:

Code:

WebBrowser1.Document.All("p_request").InvokeMember("click")
*p_reguest is a submit button id on that site

Result: Focuses field, fills it, submits. I get captcha no results.


Then i tought maybe, sites javascript somehow monitors if i move mouse cursor (for human verification, sounds stupid but i gave it a try)

Code:

Windows.Forms.Cursor.Position = New Point(644, 515)  ' Moves cursor to submit button
            'mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0) 'mouse left button down
            mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0) ' mouse left button up

Result: Focuses field, fills it, moves cursor to submit button, clicks it. And again captcha no results.

Funny thing is that when i leave code as it is ( will not make submit query part) and run it and manualy press submit on form then it works ok, no captcha :confused:


I really appreaciate if anyone has time to check it out and can give some ideas for me what to try next.


Regards

Viewing all articles
Browse latest Browse all 27349

Trending Articles