Chromedriver: 如何禁用PDF插件

3
为了模仿我Firefox配置文件的功能,我需要确保Chrome的PDF查看器已被禁用。在互联网上搜索后,我找到的最接近的答案在这里:https://code.google.com/p/chromium/issues/detail?id=528436。然而,尝试此页面上的任何建议都没有成功。以下是我期望能够起作用的代码片段。
                Dictionary<String, Object> plugin = new Dictionary<String, Object>();
                plugin.Add("enabled", false );
                plugin.Add("name", "Chrome PDF Viewer");
                var options = new ChromeOptions();
                options.AddUserProfilePreference("plugins.plugins_list", plugin);                   

                driver = new ChromeDriver(options);

有人能看出我到底做错了什么吗?这个问题开始变得非常令人沮丧!

你是否正在尝试使用Selenium与PDF进行交互? - ddavison
您IP地址为143.198.54.68,由于运营成本限制,当前对于免费用户的使用频率限制为每个IP每72小时10次对话,如需解除限制,请点击左下角设置图标按钮(手机用户先点击左上角菜单按钮)。 - user3160829
您可以通过在地址栏中输入chrome://plugins/来禁用Chrome PDF查看器。 - Rodel Bernal
我会在测试启动时尝试做这件事。 - user3160829
3个回答

3

对于Chrome 57,我需要使用以下行:

options.AddUserProfilePreference("plugins.always_open_pdf_externally", true);

此外,如果您需要自己设置插件,则可以按照以下步骤找到它:

  1. 导航至chrome://settings/content(菜单>设置,显示高级设置...,内容设置...)。
  2. 找到特定的首选项(仅复选框)。
  3. 右键单击并检查复选框。
  4. 首选项名称是整个“pref”属性值。

0
我发现这适用于 Selenium.WebDriver 2.53m,ChromeDriver 2.25.426923 和 Chrome v55.0.2883.87 m
    var options = new ChromeOptions();
    options.AddUserProfilePreference("plugins.plugins_disabled", new []{"Chrome PDF Viewer"});
    driver = new ChromeDriver(options);

-2

这对我有用(如果第一个链接是 Chrome PDF Viewer

        driver.Navigate().GoToUrl("chrome://plugins/");
        Thread.Sleep(4000);
        driver.FindElement(By.LinkText("Disable")).Click();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接