Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome 如何使用Selenium和ChromeDriver下载文件_Google Chrome_Selenium_Webdriver_Selenium Chromedriver - Fatal编程技术网

Google chrome 如何使用Selenium和ChromeDriver下载文件

Google chrome 如何使用Selenium和ChromeDriver下载文件,google-chrome,selenium,webdriver,selenium-chromedriver,Google Chrome,Selenium,Webdriver,Selenium Chromedriver,我有一个网站要用selenium和ChromeDriver(在windows上)进行测试,我喜欢在那里测试导出数据和再次导入数据的功能 导出将创建一个xml文件,该文件将下载到一台计算机上。当使用webdriver运行此程序时,Chrome会询问我是保留该文件还是丢弃该文件,因为它可能会造成潜在威胁 如何在测试中关闭此行为?是否有一个chrome设置我可以使用,这样无论下载什么文件都可以使用 谢谢,试试这个。在windows上执行 () 试试这个。在windows上执行 () 下面的程序将帮助您

我有一个网站要用selenium和ChromeDriver(在windows上)进行测试,我喜欢在那里测试导出数据和再次导入数据的功能

导出将创建一个xml文件,该文件将下载到一台计算机上。当使用webdriver运行此程序时,Chrome会询问我是保留该文件还是丢弃该文件,因为它可能会造成潜在威胁

如何在测试中关闭此行为?是否有一个chrome设置我可以使用,这样无论下载什么文件都可以使用


谢谢,试试这个。在windows上执行

()


试试这个。在windows上执行

()


下面的程序将帮助您下载Chrome中的文件 期望的能力。这是一个丰富的课程,有很多实用工具,你可以在空闲时间学习

public class DownloadChromeFile {
       public static void main(String[] args) {
       System.setProperty("webdriver.chrome.driver","./chromedriver.exe");
       String downloadFilepath = "c:\\download";

       HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
       chromePrefs.put("profile.default_content_settings.popups", 0);
       chromePrefs.put("download.default_directory", downloadFilepath);
       ChromeOptions options = new ChromeOptions();
       HashMap<String, Object> chromeOptionsMap = new HashMap<String, Object>();
       options.setExperimentalOption("prefs", chromePrefs);
       options.addArguments("--test-type");
       options.addArguments("--disable-extensions"); //to disable browser extension popup

       DesiredCapabilities cap = DesiredCapabilities.chrome();
       cap.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap);
       cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); // Bydefault it will accepts all popups.
       cap.setCapability(ChromeOptions.CAPABILITY, options);
       driver = new ChromeDriver(cap);  
                driver.get("Your Application Url");
                driver.findElement(By.xpath("Export Button xpath")).click();
        }
} 
公共类下载chromefile{
公共静态void main(字符串[]args){
System.setProperty(“webdriver.chrome.driver”,“/chromedriver.exe”);
String downloadFilepath=“c:\\download”;
HashMap chromePrefs=新HashMap();
chromePrefs.put(“profile.default\u content\u settings.popups”,0);
chromePrefs.put(“download.default\u目录”,downloadFilepath);
ChromeOptions选项=新的ChromeOptions();
HashMap chromeOptionsMap=新HashMap();
选项。设置实验选项(“prefs”,chromePrefs);
options.addArguments(“--test type”);
options.addArguments(“--disable extensions”);//禁用浏览器扩展弹出窗口
DesiredCapabilities=DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY,ChromeOptions sMap);
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true);//默认情况下,它将接受所有弹出窗口。
上限设置能力(色度选项、能力、选项);
驱动器=新的镀铬驱动器(cap);
获取(“您的应用程序Url”);
findElement(By.xpath(“导出按钮xpath”))。单击();
}
} 

下面的程序将帮助您使用Chrome下载文件 期望的能力。这是一个丰富的课程,有很多实用工具,你可以在空闲时间学习

public class DownloadChromeFile {
       public static void main(String[] args) {
       System.setProperty("webdriver.chrome.driver","./chromedriver.exe");
       String downloadFilepath = "c:\\download";

       HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
       chromePrefs.put("profile.default_content_settings.popups", 0);
       chromePrefs.put("download.default_directory", downloadFilepath);
       ChromeOptions options = new ChromeOptions();
       HashMap<String, Object> chromeOptionsMap = new HashMap<String, Object>();
       options.setExperimentalOption("prefs", chromePrefs);
       options.addArguments("--test-type");
       options.addArguments("--disable-extensions"); //to disable browser extension popup

       DesiredCapabilities cap = DesiredCapabilities.chrome();
       cap.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap);
       cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); // Bydefault it will accepts all popups.
       cap.setCapability(ChromeOptions.CAPABILITY, options);
       driver = new ChromeDriver(cap);  
                driver.get("Your Application Url");
                driver.findElement(By.xpath("Export Button xpath")).click();
        }
} 
公共类下载chromefile{
公共静态void main(字符串[]args){
System.setProperty(“webdriver.chrome.driver”,“/chromedriver.exe”);
String downloadFilepath=“c:\\download”;
HashMap chromePrefs=新HashMap();
chromePrefs.put(“profile.default\u content\u settings.popups”,0);
chromePrefs.put(“download.default\u目录”,downloadFilepath);
ChromeOptions选项=新的ChromeOptions();
HashMap chromeOptionsMap=新HashMap();
选项。设置实验选项(“prefs”,chromePrefs);
options.addArguments(“--test type”);
options.addArguments(“--disable extensions”);//禁用浏览器扩展弹出窗口
DesiredCapabilities=DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY,ChromeOptions sMap);
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true);//默认情况下,它将接受所有弹出窗口。
上限设置能力(色度选项、能力、选项);
驱动器=新的镀铬驱动器(cap);
获取(“您的应用程序Url”);
findElement(By.xpath(“导出按钮xpath”))。单击();
}
} 

我不相信你可以在飞行中,但如果你真的需要它,也许这将帮助你添加参数
——禁用网络安全
——安全浏览禁用下载保护
。我不相信你可以在飞行中,但如果你真的需要它,也许这将帮助你添加参数
——禁用网络安全
,以及
--安全浏览禁用下载保护