Remote webdriver - Passing firefox profile with Rest Client Extension (add-on)

随声附和 提交于 2019-11-30 13:07:12

After creating a FilefoxProfile instance, transfer the profile using the 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);

Note: You don't have to create a profile in advance, the FirefoxProfile API offers several convenient methods to compose a profile. For instance, if you want to launch Firefox with an extension pre-installed, use:

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);

Documentation for working with the remote web driver:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!