开发者

C# How-to send ENTER from program?

开发者 https://www.devze.com 2023-03-15 03:04 出处:网络
i am beginer and i write this code and can\'t send ENTER click from webbrowser component on C#: private void start_submit_Click(object sender, EventArgs e)

i am beginer and i write this code and can't send ENTER click from webbrowser component on C#:

private void start_submit_Click(object sender, EventArgs e)
{
    XmlDocument xdoc = new XmlDocument();
    xdoc.Load("settings.xml");             
    foreach (System.Xml.XmlNode node in xdoc.SelectNodes("//site"))
    {
        foreach (System.Xml.XmlNode child in node)
        {
                if (child.Attributes["todo"].Value.ToString() == "navigate")
                {
                    navigate(url_string);
                }
                else if (child.Attributes["todo"].Value.ToString() == "checkbox")
                {
                    HtmlElementCollection es = webBrowser1.Document.GetElementsByTagName("input");
                    HtmlElement ele0 = es[1];
                    ele0.SetAttribute("checked", "true");
                }
                else if (child.Attributes["todo"].Value.ToString() == "pressbutton")
                {
                    HtmlElementCollection es = webBrowser1.Document.GetElementsByTagName("input");
                    if (es != null && es.Count != 0)
                    {
                        HtmlElement ele = es[5];
                        ele.ScrollIntoView(true);
                        ele.Focus();
                        SendKeys.Send("{ENTER}");
                   }                           
                }
                else if (child.Attributes["todo"].Value.ToString() == "wait")
                {
                    MessageBox.Show("waiting...");
                 }
        }
    }
}

and settings.xml file:

<?xml version="1.0" encoding="utf-8" ?>
  <data>
    <site开发者_如何转开发 num="1" name="http://www.clantemplates.com" pr="5">
    <step num="1" todo="navigate" value_todo="http://www.clantemplates.com/forums/register.php" value_2_todo="none">navigating</step>
    <step num="2" todo="checkbox" value_todo="true" value_2_todo="8">checking checkbox</step>
    <step num="3" todo="pressbutton" value_todo="enter" value_2_todo="9">pressing button</step>
    <step num="4" todo="wait" value_todo="" value_2_todo="">waiting for other click</step>
  </site>
</data>

without this piece ENTER sends succesfully

else if (child.Attributes["todo"].Value.ToString() == "wait")
{
    MessageBox.Show("waiting...");
}

with piece - no

how to solve?

Thanks!


Solved, i do that with:

HtmlElementCollection es = webBrowser1.Document.GetElementsByTagName("input");
HtmlElement ele = es[5];
ele.InvokeMember("Click");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号