2

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!

2
  • Try doing webBrowser1.Select() before doing SendKeys.Send(). Commented Jun 23, 2011 at 13:53
  • i do webBrowser1.Select(); SendKeys.Send("{ENTER}"); and in program appears that input button in webbrowser active and anything else Commented Jun 23, 2011 at 14:19

1 Answer 1

2

Solved, i do that with:

HtmlElementCollection es = webBrowser1.Document.GetElementsByTagName("input"); HtmlElement ele = es[5]; ele.InvokeMember("Click"); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.