2016-08-03 30 views
1

我開發了一個項目,從我使用的web瀏覽器一個website.so拿數據和設置的URL travelchi.ir和我寫了下面的代碼如何設置HTML元素的值在C#

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) 
     { 
      HtmlDocument doc = webBrowser1.Document; 
      HtmlElement Source = doc.GetElementById("from"); 
      HtmlElement Destination = doc.GetElementById("to"); 
      HtmlElement adultCount = doc.GetElementById("adultCount"); 
      HtmlElement childCount = doc.GetElementById("childCount"); 
      HtmlElement infantCount = doc.GetElementById("infantCount"); 
      var links = webBrowser1.Document.GetElementsByTagName("button"); 
      var inputs = webBrowser1.Document.GetElementsByTagName("input"); 
      Source.SetAttribute("value", "شیراز"); 
      Destination.SetAttribute("value", "تهران"); 
      adultCount.SetAttribute("value", "1 بزرگسال"); 
      childCount.SetAttribute("value", "1 کودک"); 
      infantCount.SetAttribute("value", "0 خردسال"); 
      foreach (HtmlElement input in inputs) 
      { 
       if (input.GetAttribute("className") == "form-control") 
       { 
        input.SetAttribute("value", "1395/05/14"); 
       } 
      } 

      foreach (HtmlElement link in links) 
      { 
       if (link.GetAttribute("className") == "btn btn-primary") 
       { 
        link.InvokeMember("click"); 
       } 
      } 

到getelement與設定值它,因此最後我ecounter此代碼不能設置值,請幫我解決這個問題

+6

這看起來並不像JavaScript –

+0

還請提供錯誤它給你。 – ste2425

+0

這不是錯誤,它不能設置源和目標的值 – saba

回答