繁体   English   中英

GeckoFX-获取GetHtmlElementById

[英]GeckoFX - Get GetHtmlElementById

我已经为此苦了5个多小时

例:

 <div id='xx'>content</div> 

如何通过GetHtmlElementById或其他任何基于“ Id”的解决方案访问该div的内容

我试过了

GeckoElement el = browser.Document.GetElementById("xx");
MessageBox.Show(el.TextContent); 

和即时获取NullRefferenceException(对象引用未设置为对象的实例。)

其他示例:导航到google.co.uk

browser.DocumentCompleted += delegate { 
                MessageBox.Show(browser.DomDocument.GetElementById("gbqfsa").TextContent);

            };

MessageBox应该显示“ Google搜索”,但没有运气

用户代码未处理System.NullReferenceException
Message =对象引用未设置为对象的实例。
Source = gecko fx StackTrace:位于C:\\ Users \\ drs \\ AppData \\ Local \\ Temporary Projects \\ gecko fx \\ Form1.cs:Gecko.GeckoWebBrowser.OnDocumentCompleted(EventArgs e )在C:\\ Users \\ hindlet \\ Documents \\ Visual Studio 2010 \\ Projects \\ geckofx-15.0 \\ Geckofx-Winforms \\ GeckoWebBrowser.Events.cs:Gecko.GeckoWebBrowser.Gecko.nsIWebProgressListener.OnStateChange(nsIWebProgress aWebProgress,nsIRequest UInt32 aStateFlags,Int32 aStatus)在C:\\ Users \\ hindlet \\ Documents \\ Visual Studio 2010 \\ Projects \\ geckofx-15.0 \\ Geckofx-Winforms \\ GeckoWebBrowser.cs:line 1700 InnerException:

            GeckoHtmlElement ele;
            ele = geckoWebBrowser1.Document.GetHtmlElementById("myData");
            MessageBox.Show(ele.GetAttribute("Value"));

这对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM