创建FirefoxProfile
实例后,使用DesiredCapabilities
API ( FirefoxDriver.PROFILE
= "firefox_profile" ) 传输配置文件:
File profileDirectory = new File("c://mach//lib//prof");
FirefoxProfile profile = new FirefoxProfile(profileDirectory);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
注意:您不必提前创建配置文件,FirefoxProfile
API 提供了几种方便的方法(“方法摘要”部分)来编写配置文件。例如,如果您想启动预装扩展的 Firefox,请使用:
FirefoxProfile firefoxProfile = new FirefoxProfile();
File extension = new File("extension.xpi");
firefoxProfile.addExtension(extension);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
使用远程 Web 驱动程序的文档: