更新时间:2022-12-06 13:38:42
To use a new Firefox Profile through FirefoxOptions
you can use the following code block:
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");
To use an existing Firefox Profile through FirefoxOptions
you can use the following code block:
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");
要使用新的 Firefox配置文件通过 FirefoxOptions
以及
To use an new Firefox Profile through FirefoxOptions
along with preferences you can use the following code block:
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");
您可以在以下位置找到几个相关的详细讨论:
You can find a couple of relevant detailed discussions in: