【问题标题】:Watin and PDF'sWatin 和 PDF
【发布时间】:2008-10-13 16:58:52
【问题描述】:

谁能提供使用 Watin 下载 PDF 文件的示例?我尝试了 SaveAsDialogHandler 但我无法弄清楚。或许可以使用 MemoryStream?

谢谢,

--jb

【问题讨论】:

    标签: pdf watin


    【解决方案1】:
    FileDownloadHandler fileDownloadHandler = new FileDownloadHandler(file.FullName);
    using (new UseDialogOnce(ie.DialogWatcher, fileDownloadHandler))
    {
        ie.Button("exportPdfButtonId").ClickNoWait();
    
        fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(30);
        fileDownloadHandler.WaitUntilDownloadCompleted(200);
    }
    

    【讨论】:

      【解决方案2】:

      这段代码可以解决问题。 UsedialogOnce 类可以在 WatiN.UnitTests 代码中找到,它将成为 WatiN 1.3 版本的一部分(可能会在 10 月 14 日发布)。

      FileDownloadHandler fileDownloadHandler = new FileDownloadHandler(file.FullName); 使用 (new UseDialogOnce(ie.DialogWatcher, fileDownloadHandler)) { ie.Button("exportPdfButtonId").ClickNoWait();

      fileDownloadHandler.WaitUntilFileDownloadDialogIsHandled(30);
      fileDownloadHandler.WaitUntilDownloadCompleted(200);
      

      }

      HTH, 杰伦·范梅宁 首席开发者WatiN

      【讨论】:

        【解决方案3】:

        我刚刚遇到了同样的问题,只是我使用 Foxit 而不是 Acrobat。我告诉 Foxit 不要在浏览器中运行,然后这段代码开始正常工作。这是一个完整的单元测试,应该可以解决问题:

                string file = Path.Combine(Directory.GetCurrentDirectory(), "test.pdf");
        
                using (IE ie = new IE())
                {
                    FileDownloadHandler handler = new FileDownloadHandler(file);
        
                    using (new UseDialogOnce(ie.DialogWatcher, handler))
                    {
                        try
                        {
                            ie.GoToNoWait("http://www.tug.org/texshowcase/cheat.pdf");
        
                            //WatiN seems to hang when IE loads a PDF, so let it timeout...
                            ie.WaitForComplete(5);
                        }
                        catch (Exception)
                        {
                            //Ok.
                        }
        
                        handler.WaitUntilFileDownloadDialogIsHandled(30);
                        handler.WaitUntilDownloadCompleted(30);
                    }
        
                }
        
                Assert.That(File.Exists(file));
        

        【讨论】:

          【解决方案4】:
          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-10-12
          相关资源
          最近更新 更多