18 Aralık 2015 Cuma

c# webbrowser xpath alma

private void wbrowser_DocumentCompleted(Object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            this.wbrowser.Document.Body.MouseDown += new HtmlElementEventHandler(Body_MouseDown);
        }
    void Body_MouseDown(Object sender, HtmlElementEventArgs e)

        {
            switch (e.MouseButtonsPressed)
            {
                case MouseButtons.Right:
                  HtmlElement   element = this.wbrowser.Document.GetElementFromPoint(e.ClientMousePosition);

                var savedId = element.Id;
                var uniqueId = Guid.NewGuid().ToString();
                element.Id = uniqueId;
                var doc = new HtmlAgilityPack.HtmlDocument();
                doc.LoadHtml(element.Document.GetElementsByTagName("html")[0].OuterHtml);
                element.Id = savedId;

                var node = doc.GetElementbyId(uniqueId);
                var xpath = node.XPath;
                this.Text = xpath;

                 break;

            }
        }