Web浏览器控件导航问题 [英] WebBrowser Control Navigation Issue

查看:70
本文介绍了Web浏览器控件导航问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个应用需要导航到某些网站,点击一些按钮/链接进行导航并最终直接下载文件。

I have an app that requires navigating to some sites, clicking some buttons/links to navigate and eventually download files directly.


我试图使用selenium Firefox驱动程序,但每次firefox获取更新时都会一直打破。

I tried to use the selenium Firefox Driver, but this keeps breaking every time firefox gets an update.


我决定改用WebBrowser Control我在网上检查了所有的例子,但由于某种原因导航没有发生,而且Documentcompleted事件没有被解雇。

I decided to use WebBrowser Control instead and I checked all the examples online but for some reason the navigation is not happening and the Documentcompleted event is not firing.


我创建了一个简单的Windows窗体来测试应用程序并将控件放入其中,它是可见的。当代码点击Navigate方法时,它会卡住,因为它永远不会执行DocumentCompleted事件。我试图删除wait方法,但是
WebControl中的文档仍然为null,而DocumentCompleted永远不会执行.Woredercompleted中的断点永远不会被命中(我把断点放在if级别)

I created a simple Windows Form to test the app and put the control in it, it is visible. When the code hits the Navigate method, it gets stuck because it never executes the DocumentCompleted event. I tried to remove the wait method but the document in the WebControl remains null and the DocumentCompleted is never executed. The breakpoint in the Documentcompleted is never hit (I put the breakpoint at the if level)


我使用的是Visual Studio 2015,我安装了Windows Pro 10.我也有IE 11和Edge,但我的默认浏览器是Chrome。(我认为这不使用Chrome) Windows应用程序运行的是.NET 4.5.2

I am using Visual Studio 2015, I have Windows Pro 10 installed. I also have both IE 11 and Edge but my default browser is Chrome. (I don't think this uses Chrome) The Windows app is running .NET 4.5.2


客户端也在运行Windows 10.我读了一些关于Windows 10更新的潜在问题的回复,以及更改注册表或卸载某些更新,但我真的不想走这条路线任何想法或替代方案?

The client is also running windows 10. I read some replies about potential issues with Windows 10 updates and to change the registry or uninstall certain updates, but I really don't want to go this route. Any ideas or alternative?


这是我导航到的页面背后的表单代码,是公开的,不需要登录。

Here is the form code behind The page I am navigating to, is public and no login is required.


  public partial class WebBrowserForm : Form
  {

        bool pageLoaded = false;

        public WebBrowserForm()
        {
            InitializeComponent();
        }

        public void TestDownload()
        {
            WebBrowser browser = new WebBrowser();
            browser.Visible = true;
            browser.AllowNavigation = true;

            pageLoaded = false;
            browser.DocumentCompleted += Browser_DocumentCompleted;
            browser.Navigate("http://apps.ahca.myflorida.com/dm_web/");
            waitForPageLoading();
                //do something else here once the page is loaded

        }

        private void Browser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            if ((sender as WebBrowser).ReadyState == System.Windows.Forms.WebBrowserReadyState.Complete)
            {
                pageLoaded = true;
            }
        }


        void waitForPageLoading()
        {
            while (pageLoaded == false)
            {
                Thread.Sleep(3000);// keep sleeping until the page is ready   
            }
        }

        private void btnTest_Click(object sender, EventArgs e)
        {
            TestDownload();
        }
    } 






推荐答案

你好daoud175,

Hello daoud175,

根据你的问题与windows表格有关,我会把线程移到

Windows Forms General
  forum 以获得合适的支持。

According to your question is more related to windows form, I will move the thread to Windows Forms General forum for suitable support.

Visual C#讨论并询问C#编程语言,IDE,库,示例和工具。如果您有一些语法或代码错误,请随时与我们联系。我们会尽力为您提供解决方案。

The Visual C# discuss and ask the C# programming language, IDE, libraries, samples and tools . If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution .

此致,

feih-7


这篇关于Web浏览器控件导航问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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