首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >使用selenium运行firefox并启用扩展

使用selenium运行firefox并启用扩展
EN

Stack Overflow用户
提问于 2018-04-16 21:52:10
回答 1查看 836关注 0票数 0

我使用的是火狐59.0.2版和selenium 3.6.0版,我的任务是在启用了扩展的火狐中运行headless .my。我一次只能执行一个任务,即我可以运行headless或午餐firefox with extension,但我无法同时执行这两个任务,因为在特定的jar .how中同时不支持这两个任务

代码语言:javascript
复制
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");
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-16 22:19:19

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

代码语言:javascript
复制
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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49858996

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档