如何在Form_Load中通过GeckoWebBrowser来控制url并以显示的形式访问DOM? [英] How can I nevigate an url through GeckoWebBrowser within Form_Load and get access the DOM in form shown ?

查看:240
本文介绍了如何在Form_Load中通过GeckoWebBrowser来控制url并以显示的形式访问DOM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参阅以下代码。



Please see the following code.

private void Form1_Load(object sender, EventArgs e)
       {

           geckoWebBrowser1.Navigate("http://localhost:62343/ReportPage.html);

       }

private void Form1_Shown(object sender, EventArgs e)
       {
           var item1 = geckoWebBrowser1.Document.GetElementById("DynamicGrid");

           htmlelem = item1.InnerHtml;
       }





问题是当我运行我的项目时,我在Form1_Shown中将item1设为null。



但是当我把这个代码放在按钮事件中时,例如





The problem is that when I run my project I get item1 as null in Form1_Shown.

But When I put this code under a button event like

private void buttonGetDom_Click(object sender, EventArgs e)
        {
             var item1 = geckoWebBrowser1.Document.GetElementById("DynamicGrid");

            htmlelem = item1.InnerHtml;

        }





然后我得到了innerhtml。如何在Form_Shown中获取此元素的innerhtml?



请记住,我只需从Form1_Shown访问此DOM,并且我正在使用GeckoWebBrowser。 />


有人可以帮我吗?



Then I get the innerhtml. How can I Get innerhtml of this Element in Form_Shown ?

Please keep in mind that I need to access this DOM only from from Form1_Shown and I am using GeckoWebBrowser.

Can anyone help me please ?

推荐答案

在控制之前你将无法访问该文件已完成加载页面。



假设您正在使用 GeckoFX [ ^ ]库,您需要等待 DocumentCompleted 事件被引发,然后才能访问该文档。
You won't be able to access the document until the control has finished loading the page.

Assuming you're using the control from the GeckoFX[^] library, you need to wait for the DocumentCompleted event to be raised before you can access the document.


这篇关于如何在Form_Load中通过GeckoWebBrowser来控制url并以显示的形式访问DOM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆