要使用新的火狐简介 https://stackoverflow.com/questions/54661217/unknown-error-messageconnection-refused-stacktrace-while-trying-to-use/54664172#54664172通过FirefoxOptions
您可以使用以下代码块:
System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setProfile(new FirefoxProfile());
WebDriver driver = new FirefoxDriver(options);
driver.get("https://www.google.com");
使用现有的火狐简介 https://stackoverflow.com/questions/52464598/how-can-i-set-a-default-profile-for-the-firefox-driver-in-selenium-webdriver-3/52474787#52474787通过FirefoxOptions
您可以使用以下代码块:
System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile testprofile = profile.getProfile("debanjan");
FirefoxOptions opt = new FirefoxOptions();
opt.setProfile(testprofile);
WebDriver driver = new FirefoxDriver(opt);
driver.get("https://www.google.com");
要使用新的火狐简介 https://stackoverflow.com/questions/53886741/selenium-tests-take-several-minutes-to-start-when-loading-a-profile/54072337#54072337通过FirefoxOptions
随着优先 https://stackoverflow.com/questions/44074656/how-to-download-csv-file-through-firefox-profile-in-java/44084814#44084814您可以使用以下代码块:
String downloadFilepath = "C:\\path\\to\\MozillaFirefoxDownload";
System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.dir",downloadFilepath);
FirefoxOptions options = new FirefoxOptions();
options.setHeadless(true);
options.setProfile(profile);
WebDriver driver = new FirefoxDriver(options);
driver.get("https://www.google.com");
参考
您可以在以下位置找到一些相关的详细讨论:
- 无法解析构造函数 FirefoxDriver(org.openqa.selenium.firefox.FirefoxProfile) https://stackoverflow.com/questions/49683355/cannot-resolve-constructor-firefoxdriverorg-openqa-selenium-firefox-firefoxprof/49686604#49686604
- 无法在网络驱动程序中传递 FirefoxProfile 参数以使用首选项下载文件 https://stackoverflow.com/questions/47568275/unable-to-pass-firefoxprofile-parameter-in-webdriver-to-use-preferences-to-downl/47569170#47569170