English 中文(简体)
Chrome司机 117+ “Save As” Dialog - How to Bypass? (ium/贾瓦)
原标题:ChromeDriver Version 117+ Forces "Save As" Dialog - How to Bypass? (Selenium/Java)
The bounty expires in 5 days. Answers to this question are eligible for a +50 reputation bounty. Stephen wants to draw more attention to this question:
This could use more attention as the solutions don t seem to work in all cases. Chrome may also be continuing to change in this regard.

我一直在使用位于 Java的 Chrome骑手的Selenium网络司机进行自动文件下载。 我的法典正在完美地运作,直到我更新至Mokainr版本117+为止,该法典在Chatat 1160.5845.141上做了罚款,似乎在Cyreat 1160.5845.188中开始出现问题。 现在看来,浏览器正在迫使“Save As”方言箱露面,即使我为避开 preferences。

这里是我 Java法典的幻灯:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import java.util.HashMap;

public class FileDownloadHeadless {
    public static void main(String[] args) throws InterruptedException {

        System.setProperty("webdriver.chrome.driver", "path/to/chromedriver.exe");

        ChromeOptions options = new ChromeOptions();
        options.setCapability("os", "Windows");
        options.setCapability("os_version", "10");
        options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        options.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
        options.setCapability("chrome.switches", Arrays.asList("--incognito"));
        options.setCapability(ChromeOptions.CAPABILITY, options);
        options.addArguments("--headless");
        options.addArguments("--disable-gpu");

        HashMap<String, Object> chromePrefs = new HashMap<>();
        chromePrefs.put("profile.default_content_settings.popups", 0);
        chromePrefs.put("download.default_directory", "C:\local_files");
        chromePrefs.put("download.prompt_for_download", false);
        chromePrefs.put("profile.content_settings.exceptions.automatic_downloads.*.setting", 1);
        chromePrefs.put("profile.default_content_setting_values.automatic_downloads", 1);
        options.setExperimentalOption("prefs", chromePrefs);

        WebDriver driver = new ChromeDriver(options);

        driver.get("http://my_site.com/download");

        driver.findElement(By.id("id_button_download")).click();

        Thread.sleep(5000);

        driver.quit();
    }
}

尽管有这些条件,“Save As”方言箱仍然出现,扰乱了自动化流程。 我尝试了 Chrome喜的多种组合,但似乎没有人绕过第117版的新行为。

是否有任何其他人在“ Chrome”式117+或更高时遇到这一问题? 如果是的话,你如何围绕这一最新情况开展工作? 任何见解都将受到高度赞赏。

取消“国家义务”所建议的“承认”模式确实奏效! 但我想知道,这种方式如何实际影响档案下载选择。 如果任何人在保持冷静态度的同时,能找到另一个解决问题的办法,我将不胜感激。

感谢你的时间和援助。

最佳回答

I just remove --incognito It working

问题回答

如果你需要保持Incognito模式,那么你就可以避免“拯救儿童联盟”与以下组织(在Adhur)发生联系。

options = ChromeOptions()
options.add_argument( incognito )
options.add_argument( disable-features=DownloadBubble,DownloadBubbleV2 )

Solution: If you re like me, you need to launch chrome in incognito. In my case it s to force a different login, so simply removing --incognito is not an option.

As of 117, 所有下载均以内识别方式进行,将迫使“拯救儿童”作为方言箱,而不论你所写的 Chrome。

(Python Solutions-但应当能够轻易地向 Java翻译

为了解决这个问题,我们需要树立两条旗帜。 你可以这样做,根据你的神职制度, following清以下法律。 加入:

chromeLocalStatePrefs = { browser.enabled_labs_experiments : [ download-bubble@2 ,  download-bubble-v2@2 ]}
chromeOptions.add_experimental_option( localState , chromeLocalStatePrefs)

(当然,“横向选择”与你的 Chrome变数相匹配:原始选择=网络用户。 chrome_options is used, for example.)

对于使用<>Serenity-BDD的人,请在serenity.conf上添加以下选择:

"goog:chromeOptions" {
  ...
  ...
  // Fix: Chrome 117 forces "Save As" dialog to appear
  localState = {"browser.enabled_labs_experiments": ["download-bubble@2", "download-bubble-v2@2"]},
}

To execute in incognito mode, add the below lines along with your code(Java).

            List<String> enabledLabsExperiments = new ArrayList<>();
            enabledLabsExperiments.add("download-bubble@2");
            enabledLabsExperiments.add("download-bubble-v2@2");
            chromePrefs.put("browser.enabled_labs_experiments", enabledLabsExperiments);
            options.setExperimentalOption("localState", chromePrefs);

The root cause of the "Save As" dialog box appearing even with the appropriate Chrome preferences set in Selenium WebDriver with ChromeDriver version 117+ is likely due to changes or updates in ChromeDriver s handling of download behavior, particularly in incognito mode. These updates might have altered how Chrome interprets or applies download preferences, causing the "Save As" dialog to appear despite settings intended to suppress it. The issue s resolution upon removing "--incognito" suggests that incognito mode specifically affects how download preferences are enforced or recognized in these newer versions.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签