![](/img/trans.png)
[英]Java - Selenium WebDriver - How do I check if the File Download Dialog Box is visible? (Not download Only visibility)
[英]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();}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.