Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Thank you everyone. After thinking and programming for a almost whole day, I came to decision that i have to use native htmlElement instead of htmlagilitypack HtmlNode, because I want to input text into Htmlelement in webbrowser . so here is the code that i came up with. still i would appreciate if someone shows a solution with htmlagilitypack.</p> <pre><code> public HtmlElement selectHtmlNode(string xPath, HtmlElement htmlElement) { string currentNode; int indexOfElement; //get string representation of current Tag. if (xPath.Substring(1,xPath.Length-2).Contains('/')) currentNode = xPath.Substring(1, xPath.IndexOf('/', 1) - 1); else currentNode = xPath.Substring(1, xPath.Length-1); //gets the depth of current xPath int numOfOccurence = Regex.Matches(xPath, "/").Count; //gets the children's index int.TryParse(Regex.Match(currentNode, @"\d+").Value, out indexOfElement); //if i have to select nth-child ex: /tr[4] if (indexOfElement &gt; 1) { currentNode = currentNode.Substring(0, xPath.IndexOf('[') - 1); //the tag that i want to get if (numOfOccurence == 1 || numOfOccurence == 0) { return htmlElement.Children[indexOfElement - 1]; } //still has some children tags if (numOfOccurence &gt; 1) { int i = 1; //select nth-child foreach (HtmlElement tempElement in htmlElement.Children) { if (tempElement.TagName.ToLower() == currentNode &amp;&amp; i == indexOfElement) { return selectHtmlNode(xPath.Substring(xPath.IndexOf('/', 1)), tempElement); } else if (tempElement.TagName.ToLower() == currentNode &amp;&amp; i &lt; indexOfElement) { i++; } } } } else { if (numOfOccurence == 1 || numOfOccurence == 0) { return htmlElement.FirstChild; } if (numOfOccurence &gt; 1) { foreach (HtmlElement tempElement in htmlElement.Children) { if (tempElement.TagName.ToLower() == currentNode) { return selectHtmlNode(xPath.Substring(xPath.IndexOf('/', 1)), tempElement); } } } } return null; } </code></pre> <p>function is called in this way. where htmlController is instance of some class.</p> <pre><code>HtmlElement currentElement = htmlController.selectHtmlNode("/body/form/div/div[2]/div/div/input", webBrowser.Document.GetElementsByTagName("html")[0]); currentElement.SetAttribute("Value", "hello world"); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload