【问题标题】:unable to launch FireFox custom profile with geckodriver in java无法在 java 中使用 geckodriver 启动 FireFox 自定义配置文件
【发布时间】:2019-01-11 00:02:56
【问题描述】:

我正在尝试使用 selenium v​​3.12 和 gecko-driver v2.10 以及 Firefox 版本 60.0 启动一个带有附加组件的 Firefox 配置文件,但似乎自定义配置文件不起作用。下面是我的代码

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

实际错误就行了

driver = new FirefoxDriver(myprofile);

作为

构造函数 FirefoxDriver(FirefoxProfile) 未定义

【问题讨论】:

    标签: java firefox geckodriver


    【解决方案1】:

    您必须通过 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);
    

    如果以下解决方案导致 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);
    

    【讨论】:

    • 似乎正在工作,但现在在线程“main”中出现异常 java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOfRange(Unknown Source) at java.lang.String。 (Unknown Source) at java.lang.StringBuilder.toString(Unknown Source) at org.openqa.selenium.json.JsonOutput.asString(JsonOutput.java:282) at org.openqa.selenium.json.JsonOutput.lambda $new$2(JsonOutput.java:110)at org.openqa.selenium.json.JsonOutput$$Lambda$51/11830049.consume(Unknown Source)
    • 您检查过您的 Firefox 配置文件大小吗?尝试清除缓存,然后重试。
    • 不知道怎么解决这个问题
    • 添加了另一种方法,请测试@Prasad_Joshi
    猜你喜欢
    • 1970-01-01
    • 2017-06-23
    • 2018-01-13
    • 2020-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-06
    • 1970-01-01
    相关资源
    最近更新 更多