2016-03-03 16 views
-1

我有下面的代碼,網頁文本框onclick事件火的時候,我從我的WinForm文本框搜索,然後點擊搜索按鈕,但網頁文本框中onclick事件沒有被解僱。這個怎麼做?這裏是:http://www.heathrow.com/arrivals當我點擊搜索按鈕頁面仍然相同的位置,顯示在第二個數字圖像。 Internet Explorer的11我已經安裝了如何從WinForm的文本框

private void button2_Click(object sender, EventArgs e) 
{ 
     HtmlDocument doc = webBrowser1.Document; 
      HtmlElement HTMLControl2 = doc.GetElementById("searchInput"); 

      if (HTMLControl2 != null) 
      { 
       // HTMLControl2.Style = "display: none"; 
       HTMLControl2.InnerText = textBox1.Text; 

       HTMLControl2.Focus(); 

       SendKeys.SendWait("{ENTER}"); 
       textBox1.Focus(); 

      } 

} 

enter image description here

enter image description here

+0

不太清楚你問什麼。即使我直接輸入字符串「aa」,然後按下「Enter」鍵,什麼都不會發生。那麼你在該頁面上期望的行爲是什麼? – Sakura

+0

其清晰?現在呢? –

+0

當您輸入足夠多的6個字符時,該網站將自動處理該文本,如果不是,則會忽略。與瀏覽器一樣。 – Sakura

回答

1

下面是代碼:

Form1.cs中:

private void textBox1_TextChanged(object sender, EventArgs e) 
{ 
    HtmlDocument doc = webBrowser1.Document; 
    HtmlElement HTMLControl2 = doc.GetElementById("searchInput"); 

    if (HTMLControl2 != null) 
    { 
     // HTMLControl2.Style = "display: none"; 
     HTMLControl2.InnerText = textBox1.Text; 

     HTMLControl2.Focus(); 

     SendKeys.SendWait("{ENTER}"); 
     textBox1.Focus(); 

    } 
} 

還有什麼是默認的。

+0

它作爲我的應用程序相同;( –

+0

是的,正如我說多一個測試,當頁面加載完成後,你複製一個航班號,並粘貼到你的WinForms文本框,然後點擊搜索,看看是否有任何。 – Sakura

+1

此代碼可以幫助我;) SendKeys.Send(「{ENTER}」); textBox1.Focus(); HTMLControl2.Focus(); HTMLControl2.InnerText = textBox1.Text; SendKeys.Send(「{ENTER}」); textBox1.Focus(); HTMLControl2.Focus(); –

0
HtmlDocument doc = webBrowser1.Document; 
    HtmlElement HTMLControl2 = doc.GetElementById("searchInput"); 

    if (HTMLControl2 != null) 
    { 
     // HTMLControl2.Style = "display: none"; 
     HTMLControl2.InnerText = textBox1.Text; 
       SendKeys.Send("{ENTER}"); 
       textBox1.Focus(); 
       HTMLControl2.Focus(); 
       HTMLControl2.InnerText = textBox1.Text; 
       SendKeys.Send("{ENTER}"); 
       textBox1.Focus(); 
       HTMLControl2.Focus(); 
} 
+0

這是一個小技巧。但它的工作,那麼確定:) – Sakura

相關問題