Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# VB
I have a small project that I'm stuck on.I'm trying to create an app to create Yahoo email accounts. The problem with the code is that the click action generates this error: "Looks like there was some trouble creating your account. Please take a moment to review your answers."
But when I manually click in the webbrowser control it works fine to get to the next page.
 
Public Class Form1
    Dim _maryFirst() As String
    Dim _maryLast() As String
    Dim _maryZip() As String
    Dim _mstrPass As String
    Private Sub btnSignup_Click(sender As Object, e As EventArgs) Handles btnSignup.Click
        WebBrowser1.Navigate("https://eu.edit.yahoo.com/registration")
        WebBrowser1.ScriptErrorsSuppressed = True
        _mstrPass = RandomString(10)
    End Sub
 
    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        Dim strLastname As String
        WebBrowser1.ScriptErrorsSuppressed = True
        strLastname = _maryLast(CInt(Int((2323 * Rnd()))))
        With WebBrowser1.Document
            If .Url.AbsoluteUri = "https://na.edit.yahoo.com/registration?.pd=&intl=us&origIntl=&done=&src=&last=&partner=yahoo_default&domain=&yahooid=&lang=en-US" Then
                .GetElementById("firstname").SetAttribute("value", _maryFirst(CInt(Int((810 * Rnd())))))
                .GetElementById("secondname").SetAttribute("value", strLastname)
                .GetElementById("yahooid").SetAttribute("value", strLastname & CInt(Int((9999 * Rnd()) + 1001)))
                .GetElementById("password").SetAttribute("value", _mstrPass)
                .GetElementById("passwordconfirm").SetAttribute("value", _mstrPass)
                .GetElementById("mm").SetAttribute("value", CInt(Int((12 * Rnd()) + 1)))
                .GetElementById("dd").SetAttribute("value", CInt(Int((25 * Rnd()) + 1)))
                .GetElementById("yyyy").SetAttribute("value", CInt(Int(((1980 - 1950) * Rnd()) + 1950)))
                .GetElementById("gender").SetAttribute("value", "f")
                .GetElementById("postalcode").SetAttribute("value", _maryZip(CInt(Int(29469 * Rnd()))))
                .GetElementById("IAgreeBtn").InvokeMember("click")
            End If
        End With
    End Sub
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        _maryFirst = IO.File.ReadAllLines(Application.StartupPath() & "\firstnames.txt")
        _maryLast = IO.File.ReadAllLines(Application.StartupPath() & "\lastnames.txt")
        _maryZip = IO.File.ReadAllLines(Application.StartupPath() & "\zip.txt")
 
    End Sub
 
    Private Shared Function RandomString(cb As Integer) As String
 
        Randomize()
        Dim rgch As String
        rgch = "abcdefghijklmnopqrstuvwxyz"
        rgch = rgch & UCase(rgch) & "0123456789"
        RandomString = ""
        ' ReSharper disable NotAccessedVariable
        Dim i As Long
        ' ReSharper restore NotAccessedVariable
        For i = 1 To cb
            RandomString = RandomString & Mid$(rgch, Int(Rnd() * Len(rgch) + 1), 1)
        Next
 
    End Function
 
End Class
 
Commenting out
.GetElementById("IAgreeBtn").InvokeMember("click")
then run the program and click on the "create my account" button in the web browser control will complete the first page of the process. This tells me that there is an issue with the above line of code that somehow isn't working the same way as manually clicking the button.
Posted 24-Dec-12 9:01am
Comments
John d. Bartels at 2-Jan-13 0:28am
   
Instead of trying to invoke the click on the actual button, you could also try the Win32 mouse_event to make this happen.
Member 7781963 at 2-Jan-13 0:53am
   
How to do that? Kindly show me the code.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Declare Function mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Int32, ByVal dX As Int32, ByVal dY As Int32, ByVal cButtons As Int32, ByVal dwExtraInfo As Int32) As Boolean 
 
Taken From MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646260(v=vs.85).aspx[^]
 
For this to work, the window must have focus (because you are simulating a mouse click), you can use the win32 api call SetForegroundWindow to make this happen. (unless the window already has focus) This same mouse_event function can be used to move the mouse, and to click the button.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 565
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 3 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100