0

live.comよし、これを介して にログインするスクリプトがあります。

     WebBrowser1.Document.GetElementById("login").SetAttribute("value", txtUsername.Text)
     WebBrowser1.Document.GetElementById("passwd").SetAttribute("value", txtPassword.Text)
     WebBrowser1.Document.GetElementById("SI").InvokeMember("Click")

これはかなり基本的なことですが、ここで必要なのは、ユーザーが入力したアカウント資格情報が正しいか間違っているかを調べることです。したがって、これには「ログインできませんでした」というエラー メッセージが必要ですが、成功した場合は、Web ブラウザーを新しいページにリダイレクトするだけです。今、私はVBのIFステートメントに慣れていませんが、これを行うには2つの方法があることは知っていますが、その方法はわかりません. したがって、最初の方法は、送信ボタンを押した後に移動する URL を読み取ることです。これは非常にうまく機能します (したがって、誰かが間違ったアカウント資格情報を入力すると、エラー ページに送信されますが、正しいものを入力すると、正しいページに移動します)。しかし、私がやりたい主な方法は、コンテンツを読むことです。That Microsoft account doesn't exist. Enter a different email address or get送信後にページに " " と表示された場合、メッセージ ボックス "Wrong Account Credentials"、逆もまた然りです。WebBrowser を実際に使用したことがないので、これは苦手ですが、誰かが私を正しい方法に導くことができれば、非常に感謝しています。

4

1 に答える 1

0

Web ブラウザーで返される内容で評価したい場合は、入力したパスワードの結果として読み込まれるドキュメントの innerhtml を検索できます。

 With WebBrowser1

        Do Until Not (.IsBusy)
            Application.DoEvents()
        Loop

        Do Until .ReadyState = WebBrowserReadyState.Complete
            Application.DoEvents()
        Loop


    End With

    Dim htmlText As String

    If Not (WebBrowser1.Document.Body.InnerHtml) Is Nothing Then

        htmlText = WebBrowser1.Document.Body.InnerHtml

        If InStr(htmlText, "That Microsoft account doesn't exist.") Then

            Messagebox.Show("Wrong Account Credentials")
            'code to go here if it is true

        Else

            Messagebox.Show("Correct Account Credentials")
            'code to go here if it is false


        End If

    End If

注: innerhtml が機能しない場合は、outerhtml も試すことができます。

一度だけ確認したいので、最初のログイン以外のさまざまな理由で起動する .DocumentChanged イベントハンドラーを削除してみてください。ログイン時に「クリック」イベントを呼び出した後に呼び出されるサブルーチンとして置き換えます。

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
    WebBrowser1.Document.GetElementById("login").SetAttribute("value", txtUsername.Text)
    WebBrowser1.Document.GetElementById("passwd").SetAttribute("value", txtPassword.Text)
    WebBrowser1.Document.GetElementById("SI").InvokeMember("Click")

    verifyLogin()

End Sub


Private Sub verifyLogin()


    With WebBrowser1

        Do Until Not (.IsBusy)
            Application.DoEvents()
        Loop

        Do Until .ReadyState = WebBrowserReadyState.Complete
            Application.DoEvents()
        Loop


    End With

    Dim htmlText As String

    If Not (WebBrowser1.Document.Body.InnerHtml) Is Nothing Then

        htmlText = WebBrowser1.Document.Body.InnerHtml

        If InStr(htmlText, "Microsoft account") Then

            MessageBox.Show("You have entered in a wrong password or the account doesn't exist.")

            'code to go here if it is true
        Else

            MessageBox.Show("Sign in successful. Proceed on...")

            'code to go here if it is false


        End If

    End If

End Sub
于 2013-03-24T11:20:19.863 に答える