Vb.net 单击功能不工作

Vb.net 单击功能不工作,vb.net,Vb.net,我有一个小项目,我一直在做。我正在尝试创建一个应用程序来创建雅虎电子邮件帐户。代码的问题是,单击操作生成此错误:“看起来创建帐户时遇到了一些问题。请花点时间查看您的答案。” 但是,当我手动单击webbrowser控件时,可以很好地进入下一页 Public Class Form1 Dim _maryFirst() As String Dim _maryLast() As String Dim _maryZip() As String Dim _mstrPass As

我有一个小项目,我一直在做。我正在尝试创建一个应用程序来创建雅虎电子邮件帐户。代码的问题是,单击操作生成此错误:“看起来创建帐户时遇到了一些问题。请花点时间查看您的答案。” 但是,当我手动单击webbrowser控件时,可以很好地进入下一页

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
评出

.GetElementById("IAgreeBtn").InvokeMember("click")

然后运行该程序并单击web浏览器控件中的“创建我的帐户”按钮将完成该过程的第一页。这告诉我,上面这行代码存在一个问题,它的工作方式与手动单击按钮不同。

根据代码,问题可能是,web浏览器控件和按钮代码针对yahoo的两个不同区域运行:web浏览器使用na,按钮使用eu。

有人告诉我,
IAgreeBtn
不是
输入
元素。如果问题是纯问题,请不要包含C标记VB@MichaelPerrenoud我刚刚再次检查了
,如何解决此问题?确定要针对哪个区域进行身份验证,并将两个URL更改为该区域。在一个示例中,您有
https://na.
,我假设它是北美,而在另一个地方你有
https://eu.
我假设是欧洲。