运行 使用 selenium 启用扩展的 firefox
Running firefox with extension enabled using selenium
我使用的是 firefox 版本 59.0.2 和 selenium 版本 -3.6.0。我的任务是 运行 在带有扩展名的 firefox 中无头 enabled.I 我一次只能做一个任务时间,即我可以 运行 headless 或 lunch firefox with extension 但我无法同时执行这两项操作,因为在特定的 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");
像这样使用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);
我使用的是 firefox 版本 59.0.2 和 selenium 版本 -3.6.0。我的任务是 运行 在带有扩展名的 firefox 中无头 enabled.I 我一次只能做一个任务时间,即我可以 运行 headless 或 lunch firefox with extension 但我无法同时执行这两项操作,因为在特定的 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");
像这样使用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);