简体   繁体   English

无法在Java中使用geckodriver启动FireFox自定义配置文件

[英]unable to launch FireFox custom profile with geckodriver in java

I'm trying to launch a Firefox profile with add-ons in it, with selenium v3.12 and gecko-driver v2.10 and Firefox version 60.0, how-ever it seems that the custom profile is not working. 我正在尝试使用selenium v​​3.12和gecko-driver v2.10和Firefox 60.0版本启动包含附件的Firefox配置文件,但是自定义配置文件似乎无法正常运行。 below is my code 下面是我的代码

static WebDriver driver;
ProfilesIni profile = new ProfilesIni();
        myprofile = profile.getProfile("AutoProfile");
System.setProperty("webdriver.gecko.driver", 
  "E:\\Library\\geckodriver-v0.21.0-win32\\geckodriver.exe");
        driver = new FirefoxDriver(myprofile);

the acutal error is on the line 人为错误在线上

driver = new FirefoxDriver(myprofile);

as

The constructor FirefoxDriver(FirefoxProfile) is undefined 构造函数FirefoxDriver(FirefoxProfile)未定义

You have to pass it through firefox options. 您必须通过firefox选项传递它。

System.setProperty("webdriver.gecko.driver", "E:\\Library\\geckodriver-v0.21.0-win32\\geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("AutoProfile");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setProfile(myprofile);
WebDriver driver = new FirefoxDriver(firefoxOptions);

If the below solution causes a java heap error, you could try DesiredCapabilities, like this: 如果以下解决方案导致Java堆错误,则可以尝试DesiredCapabilities,如下所示:

System.setProperty("webdriver.gecko.driver","E:\\Library\\geckodriver-v0.21.0-win32\\geckodriver.exe");
File file = new File(path_to_your_firefox_profile);
DesiredCapabilities dc = DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile(file);
dc.setCapability(FirefoxDriver.PROFILE, profile);
FirefoxDriver driver = new FirefoxDriver(dc);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用 GeckoDriver 启动 Firefox - Cannot Launch Firefox using GeckoDriver 如何通过GeckoDriver和Selenium启动Firefox浏览器 - How to launch Firefox browser through GeckoDriver and Selenium 如果使用单独的配置文件,则无法使用Firefox geckodriver,它将给出错误:java.lang.OutOfMemoryError:Java堆空间 - Not working using Firefox geckodriver if you use a separate profile, it gives an error: java.lang.OutOfMemoryError: Java heap space org.openqa.selenium.SessionNotCreatedException:无法通过 Selenium 和 Java 使用 GeckoDriver 和 Firefox 创建会话错误 - org.openqa.selenium.SessionNotCreatedException: Unable to create session error using GeckoDriver and Firefox through Selenium and Java SessionNotCreatedException:无法通过Java使用SeleniumGrid和GeckoDriver Firefox找到一组匹配的功能 - SessionNotCreatedException: Unable to find a matching set of capabilities using SeleniumGrid with GeckoDriver Firefox through Java 如何使用Geckodriver保留Firefox配置文件的缓存? - How can I retain my Firefox profile's cache with Geckodriver? 无法使用Selenium 3.0.0-beta3与Geckodriver启动Firefox 41 - Failed to launch Firefox 41 with Geckodriver using Selenium 3.0.0-beta3 无法使用 webdrivermanager - Testng - Java - Maven 启动 Firefox 81.0 - Unable to launch Firefox 81.0 with webdrivermanager - Testng - Java - Maven Firefox Webdriver 无法使用扩展启动 - Firefox Webdriver unable to launch with extension Firefox 无法在 VM 机器中启动 - Firefox unable to launch in VM machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM