Selenium webdriver (java) - 文件下载对话框
Selenium webdriver (java) - file download dialog
我关注@BeforeClass:
@BeforeClass
public static void setUpClass() {
FirefoxOptions options = new FirefoxOptions();
options.setBinary("C:\Program Files (x86)\Mozilla Firefox\firefox.exe");
System.setProperty("webdriver.gecko.driver", "C:\Users\pburgr\Desktop\geckodriver-v0.19.1-win64\geckodriver.exe");
driver = new FirefoxDriver(options);
driver.manage().window().maximize();
FirefoxProfile FF_profile = new FirefoxProfile();
FF_profile.setPreference("browser.download.folderList",2);
FF_profile.setPreference("browser.download.manager.showWhenStarting",false);
FF_profile.setPreference("browser.download.dir","C:\users\pburgr\downloads\");
FF_profile.setPreference("browser.helperApps.alwaysAsk.force", false);
FF_profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
FF_profile.setPreference("pdfjs.disabled", true);
}
但是在下载 xlsx 文件时,我卡在了下载对话框中。我错过了什么?谢谢
我将 options.setProfile(selenium_profile);
移到 setPreferences 命令后面,它起作用了
另一种方法是在 firefox.exe -p 中手动创建新的浏览器配置文件。自定义配置文件(自动下载 xls 文件)并以这种方式启动 selenium:
@BeforeClass
public static void setUpClass() {
FirefoxOptions options = new FirefoxOptions();
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile selenium_profile = allProfiles.getProfile("selenium_profile");
options.setProfile(selenium_profile);
options.setBinary("C:\Program Files (x86)\Mozilla Firefox\firefox.exe");
System.setProperty("webdriver.gecko.driver", "C:\Users\pburgr\Desktop\geckodriver-v0.20.0-win64\geckodriver.exe");
driver = new FirefoxDriver(options);
driver.manage().window().maximize();}
我关注@BeforeClass:
@BeforeClass
public static void setUpClass() {
FirefoxOptions options = new FirefoxOptions();
options.setBinary("C:\Program Files (x86)\Mozilla Firefox\firefox.exe");
System.setProperty("webdriver.gecko.driver", "C:\Users\pburgr\Desktop\geckodriver-v0.19.1-win64\geckodriver.exe");
driver = new FirefoxDriver(options);
driver.manage().window().maximize();
FirefoxProfile FF_profile = new FirefoxProfile();
FF_profile.setPreference("browser.download.folderList",2);
FF_profile.setPreference("browser.download.manager.showWhenStarting",false);
FF_profile.setPreference("browser.download.dir","C:\users\pburgr\downloads\");
FF_profile.setPreference("browser.helperApps.alwaysAsk.force", false);
FF_profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
FF_profile.setPreference("pdfjs.disabled", true);
}
但是在下载 xlsx 文件时,我卡在了下载对话框中。我错过了什么?谢谢
我将 options.setProfile(selenium_profile);
移到 setPreferences 命令后面,它起作用了
另一种方法是在 firefox.exe -p 中手动创建新的浏览器配置文件。自定义配置文件(自动下载 xls 文件)并以这种方式启动 selenium:
@BeforeClass
public static void setUpClass() {
FirefoxOptions options = new FirefoxOptions();
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile selenium_profile = allProfiles.getProfile("selenium_profile");
options.setProfile(selenium_profile);
options.setBinary("C:\Program Files (x86)\Mozilla Firefox\firefox.exe");
System.setProperty("webdriver.gecko.driver", "C:\Users\pburgr\Desktop\geckodriver-v0.20.0-win64\geckodriver.exe");
driver = new FirefoxDriver(options);
driver.manage().window().maximize();}