首页 > 解决方案 > 如何下载 PDF selenium 和 C#

问题描述

我确实在 Chrome 上放置了该配置

        ChromeOptions chromeOptions = new ChromeOptions();

        chromeOptions.AddUserProfilePreference("download.default_directory", @"C:\Downloads");
        Driver.driver = new ChromeDriver(chromeOptions);

PDF 正在浏览器中的其他选项卡中打开,我没有下载按钮。

我无法通过 id 在元素上单击。

        ActionsSU.moveElementToClick(By.XPath("/html/body"));
        ActionsSU.moveElementToClick(By.Id("download"));

标签: c#seleniumselenium-webdriver

解决方案


我有解决办法。

        chromeOptions.AddUserProfilePreference("download.default_directory", @"C:\Downloads");
        chromeOptions.AddUserProfilePreference("download.prompt_for_download", false);
        chromeOptions.AddUserProfilePreference("download.directory_upgrade", true);
        chromeOptions.AddUserProfilePreference("plugins.always_open_pdf_externally", true);

推荐阅读