运行firefox并使用selenium启用扩展

时间:2018-04-16 13:52:10

标签: selenium firefox selenium-webdriver headless

我正在使用firefox版本-59.0.2和selenium版本-3.6.0。我的任务是在启用扩展程序的firefox中运行无头。我一次只能执行一项任务,即我能够运行无头或午餐firefox有扩展名,但我不能同时做两件事,因为在特定的jar中一次都不支持这两种情况。如何做到这一点

System.setProperty("webdriver.firefox.bin", "C:\\Users\\rahul\\AppData\\Local\\Mozilla Firefox\\firefox.exe");
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");

FirefoxBinary firefoxBinary = new FirefoxBinary();
firefoxBinary.addCommandLineOptions("--headless");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setBinary(firefoxBinary);
FirefoxDriver driver = new FirefoxDriver(firefoxOptions);

String autoFilePath = "C:\\software\\autoauth-3.1.1-an+fx.xpi";
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(new File(autoFilePath));
 FirefoxDriver driver = new FirefoxDriver(profile);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
WebDriverWait wait=new WebDriverWait(driver, 60);
driver.get("http://www.google.com");

1 个答案:

答案 0 :(得分:0)

像这样使用firefoxOptions.setProfile(profile);

System.setProperty("webdriver.firefox.bin", "C:\\Users\\rahul\\AppData\\Local\\Mozilla Firefox\\firefox.exe");
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");

String autoFilePath = "C:\\software\\autoauth-3.1.1-an+fx.xpi";
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(new File(autoFilePath));

FirefoxBinary firefoxBinary = new FirefoxBinary();
firefoxBinary.addCommandLineOptions("--headless");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setBinary(firefoxBinary);
firefoxOptions.setProfile(profile);
FirefoxDriver driver = new FirefoxDriver(firefoxOptions);