如何保存在没有网址的浏览器窗口中弹出的

如何保存在没有网址的浏览器窗口中弹出的

本文介绍了如何保存在没有网址的浏览器窗口中弹出的.pdf文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用我公司网站上提供的 .pdf 文件。我不知道有任何方法可以下载它们并存储在一个文件夹中。

I am working with .pdf files that are available on my companies' website only. I am not aware of any way to download them and store in one folder.

我点击获取 .pdf file包含以下源代码:

The link that I click to get the .pdf file has the following source code:

  <a href="javascript:propertiesView('documentName')">

当我点击链接时, .pdf 文件弹出一个没有url且没有源代码的新浏览器窗口。我认为没有办法直接操作 .pdf ,然后如何保存它然后才能操作 .pdfs 来自文件夹

As I click on the link, a .pdf file pops up in a new browser window with no url and no source code. I presume that there is no way to manipulate that .pdf directly, then how can I save it then in order to manipulate the .pdfs from a folder?

谢谢

推荐答案

您可以通过简单地告诉浏览器始终将PDF文件保存到磁盘来获得好运(相信):

If that doesn't work, you are probably able to iterate through all open windows/tabs by using the switchTo() methods. Try something like this to get some insight about your opened windows (credits to Prashant Shukla):

    public void getWindows() {
        Set<String> windows = driver.getWindowHandles();

        for (String window : windows) {
            driver.switchTo().window(window);
            System.out.println(driver.getTitle());
        }
    }

下载文件的非硒解决方案将是使用apache-commons库(creadits来):

A non-selenium solution to download the file would be to use the apache-commons library (creadits to Shengyuan Lu):

org.apache.commons.io.FileUtils.copyURLToFile(URL, File)

但是这需要你知道窗口的URL,你可能用我提到的第二种方法来获取它( driver.switchTo())和 driver.getCurrentUrl()

But this would require that you know the URL of the window, which you probably are able to fetch with the second approach i mentioned (driver.switchTo()) and driver.getCurrentUrl().

这篇关于如何保存在没有网址的浏览器窗口中弹出的.pdf文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 13:20