【问题标题】:Selenium and Firefox profile settingSelenium 和 Firefox 配置文件设置
【发布时间】:2016-09-20 16:04:49
【问题描述】:

我需要您的帮助来使用 Firebug 设置我的 Firefox 配置文件。我想要的是当我通过 Selenium WebDriver 启动它时,让 Firebug 加载项与 Firefox 实例一起加载。这是我的代码示例:

final File file = new File("C:\\Program Files (x86)\\Gecko\\bin\\geckodriver.exe");
System.setProperty("webdriver.gecko.driver", file.getAbsolutePath());
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("?"); 

那么...如何设置setPreference 值,以便在 Selenium WebDriver 启动浏览器时将 Firebug 与 Firefox 一起加载?

【问题讨论】:

  • Kotoj.. 非常感谢您跟进我的问题。代码如下: final File file = new File("C:\\Program Files (x86)\\Gecko\\bin\\geckodriver.exe"); System.setProperty("webdriver.gecko.driver", file.getAbsolutePath()); final String firebugPath= "C:\\Users\\jnguyen\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\erx927l4.default\\extensions\\firebug@software.joehewitt.com.xpi"; FirefoxProfile profile = new FirefoxProfile() ;profile.addExtension(new File(firebugPath)); driver = new FirefoxDriver(profile);

标签: selenium firefox firebug


【解决方案1】:

您必须添加扩展而不是设置首选项:

final String firebugPath = "C:\\FF_Profile\\firebug.xpi";
FirefoxProfile profile = new FirefoxProfile();           
profile.addExtension(new File(firebugPath));   
WebDriver driver = new FirefoxDriver(profile);

您可以按照以下说明找到 Firebug 路径:

https://stackoverflow.com/a/8074828/432681

【讨论】:

  • Kotoj!很棒的信息。感谢您抽出宝贵时间进行我的询问。很好的帮助!
  • 很高兴,如果我的回答有帮助,请采纳;)
  • kotoj... 我试过了,但它似乎不起作用.. 没有错误消息.. 所以我不知道为什么它不起作用?无论如何谢谢kotoj!
【解决方案2】:

古筝

代码如下:

// 告诉 cucumber geckodriver 在你的环境中的位置

final File file = new File("C:\\Program Files (x86)\\Gecko\\bin\\geckodriver.exe");


// Get the absolute path to the Gecko Driver
System.setProperty("webdriver.gecko.driver", file.getAbsolutePath());


final String firebugPath= "C:\\Users\\<My username>\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\erx927l4.default\\extension s\\firebug@software.joehewitt.com.xpi";


// Set up the Firefox browser profile
FirefoxProfile profile = new FirefoxProfile();


profile.addExtension(new File(firebugPath)); 


// bring up the browser
driver = new FirefoxDriver(profile);

我尝试将这些代码添加到 cmets 部分,但它不允许我格式化文本,因此我必须将它们发布在“发布您的答案”部分中。抱歉

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-08-28
    • 1970-01-01
    • 2017-08-07
    • 2016-06-25
    • 1970-01-01
    • 2021-02-13
    • 2016-09-11
    • 1970-01-01
    相关资源
    最近更新 更多