2013-04-18 60 views
1

好了,所以這個網站http://dogwars.com/app/提交按鈕上的網頁瀏覽器的HTML元素

我在做一個應用程序,你可以登錄之類的東西。

但網站上的登錄按鈕:在VB.net

<div style="margin-left: 77px; margin-top: 20px; height: 40px;"> 
    <a href="#" onclick="document.getElementById('loginForm').submit();" class="button"><span>Login</span></a> 
    </div> 

爲我自動提交按鈕我用這個:

If curElement.GetAttribute("onclick").Equals("document.getElementById('loginForm').submit();") Then 
      curElement.InvokeMember("click") 
     End If 

但它不會自動登錄,我困惑,爲什麼它不.. ..?
有人可以幫我嗎? 這裏是我的全碼:

Public Class Form1 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 

    WebBrowser1.Navigate("http://dogwars.com/app/") 

End Sub 

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted 

    Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input") 

    For Each curElement As HtmlElement In theElementCollection 

     Dim controlName As String = curElement.GetAttribute("name").ToString 

     If controlName = "email" Then 

      curElement.SetAttribute("Value", TextBox1.Text) 

     ElseIf controlName = "password" Then 

      curElement.SetAttribute("Value", TextBox2.Text) 

     End If 

    Next 


    theElementCollection = WebBrowser1.Document.GetElementsByTagName("input") 
    For Each curElement As HtmlElement In theElementCollection 
     If curElement.GetAttribute("onclick").Equals("document.getElementById('loginForm').submit();") Then 
      curElement.InvokeMember("click") 
     End If 
    Next 
End Sub 

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 

End Sub 
End Class 
+0

你什麼意思,你要自動登錄 – 2013-04-18 04:36:31

+0

它就像一個自動登錄的事情,在那裏我在我的用戶名和密碼鍵入並加載網站進入細節並按下登錄按鈕我。 – user2293453 2013-04-18 04:37:29

+0

它如何知道您輸入密碼的時間? – 2013-04-18 04:38:06

回答

0

您是在與HTML元素複雜的事情。這是你應該做的:

  WebBrowser1.Navigate("http://dogwars.com/app/") 

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

      WebBrowser1.Document.GetElementById("email").SetAttribute("value",TextBox1.Text()) 
      WebBrowser1.Document.GetElementById("password").SetAttribute("value",TextBox2.Text()) 
      WebBrowser1.Document.GetElementById("submit").InvokeMember("click") 

這應該可能工作我還沒有測試過它。