2012-06-23 68 views
0

我正在嘗試以編程方式單擊按鈕。該按鈕位於網站的第3頁。並沒有任何ID。它只是名稱,類型和價值。按鈕的HTML代碼如下如何用vb.net以編程方式點擊HTML按鈕

<FORM NAME='form1' METHOD='post' action='/dflogin.php'> 
<INPUT TYPE='hidden' NAME='txtId' value='E712050-15'> 
<INPUT TYPE='hidden'NAME='txtassId' value='1'> 
<INPUT TYPE='hidden' NAME='txtPsw' value='HH29'> 
<INPUT TYPE='hidden' NAME='txtLog' value='0'> 
<h6 align='right'> 
<INPUT TYPE='SUBMIT' NAME='btnSub' value='Next' style='background-color:#009900; color:#fff;'></h6></FORM> 

給予我曾在2008年vb.net Express Edition的嘗試這些代碼...

For Each webpageelement As HtmlElement In allelements 

      If webpageelement.GetAttribute("value") = "Next" Then 

       webpageelement.InvokeMember("click") 

      End If 
     Next 

和2一個

theElementCollection = WebBrowser1.Document.GetElementsByTagName("INPUT") 

    For Each curElement As HtmlElement In theElementCollection 

     ctrlIdentity = curElement.GetAttribute("innerText").ToString 

     If ctrlIdentity = "Next" Then 

      curElement.InvokeMember("click") 

     End If 

    Next 

和第三一種是

 Dim l_forms = WebBrowser1.Document.GetElementsByTagName("form") 
     If l_forms.Count > 0 Then 
      l_forms.Item(0).InvokeMember("submit") 
     End If 
and 4th one is 

Do While WebBrowser1.ReadyState <> WebBrowserReadyState.Complete 
Application.DoEvents() 
Loop 
WebBrowser1.Document.Body.InnerHtml = Replace(WebBrowser1.Document.Body.InnerHtml,"NAME='btnSub'", "NAME='btnSub' id='btnSub'") 'insert id into youre button 
WebBrowser1.Document.GetElementById("btnSub").InvokeMember("click") 'click on btnSub 

and the la st one is

Dim i As Integer 
     Dim allButtons As HtmlElementCollection 

     allButtons = WebBrowser1.Document.GetElementsByTagName("input") 

     i = 0 
     For Each webpageelement As HtmlElement In allButtons 
      i += 1 
      If i = 5 Then 
       webpageelement.InvokeMember("click") 
      End If 
     Next 

這些所有代碼都無法點擊該按鈕。請點擊此按鈕建議適當的解決方案。謝謝你這麼多

+0

爲什麼不直接使用JavaScript代碼從背後 –

回答

0

像這將是一個服務器端的JavaScript和jQuery解決方案

string script = "$(document).ready(function() {$('input[name=btnSub]').trigger('click'); });"; 
ScriptManager.RegisterStartupScript(this, GetType(), "ServerControlScript", script, true); 
+0

這是爲點擊該按鈕解決方案??? – user1473832

+0

是的,只是使用jquery –

+0

可以讓你編寫完整的代碼 – user1473832

相關問題