如何发送在Web浏览器控件中按Enter键进入htmlelement

时间:2013-12-01 03:37:22

标签: c# webbrowser-control

我正在使用包含网络浏览器控件的win表单应用程序,在网页中有 一个文本框字段,我把它作为htmlelement ..

我用字符串值正确填写,然后我想发送回车键按下提交 它的价值..

到目前为止,这是我的代码:

HtmlDocument hd = wbr.Document;//wbr is web browser control
HtmlElement he = hd.GetElementById("response_field");
he.SetAttribute("value", ans);//filled correctly 
wbr.Select();
he.Focus();
he.InvokeMember("submit");
SendKeys.Send("{ENTER}");

我试过调用成员,尝试了sendkey,但没有一个工作..

怎么做?

1 个答案:

答案 0 :(得分:0)

来自MSDN - Navigated

// Navigates to the URL in the address box when 
// the ENTER key is pressed while the ToolStripTextBox has focus.
private void toolStripTextBox1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Enter)
    {
        Navigate(toolStripTextBox1.Text);
    }
}