如何使用Selenium自定义Firefox配置文件? (Java)(并通过HTML授权窗口) [英] How to use custom Firefox Profile with Selenium? (Java) (And pass HTML Authorization Window)

查看:247
本文介绍了如何使用Selenium自定义Firefox配置文件? (Java)(并通过HTML授权窗口)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Selenium与Java自定义Firefox配置文件?

解决方案

我花了一天的时间尝试做到这一点,并决定在这里分享。在网上也有一些信息,但大多数都有点复杂或不及时... ...

 这里是我的配置:
Firefox版本:12
Selenium版本:2.25
语言:Java
计算机:Macintosh
  • 输入:/Applications/Firefox.app/Contents/MacOS/firefox-bin - p(根据需要更改路径)

  • 创建一个新的配置文件,并将其保存在一个目录中。 ,如你所愿添加任何插件,修改。

  • 在Selenium中,使用:



    $ b pre> FirefoxBinary binary = new FirefoxBinary();
    文件firefoxProfileFolder = new
    文件(/ Users / xxx / work / xxx / selenium / src / test / resources / firefoxprofile);
    FirefoxProfile profile = new FirefoxProfile(firefoxProfileFolder);
    profile.setAcceptUntrustedCertificates(true);
    webDriver =新的FirefoxDriver(binary,profile);
  • 再次按需要更改绝对路径。
    添加像autoAuth这样的加载项,将Firefox中的HTML授权窗口传递给此配置文件。


    How can I use Selenium with Java with a custom Firefox Profile?

    解决方案

    I have spent a day trying to do this and decided to share it here. There is some information on the web as well but most of them are a bit complicated or not up to date...

    Here is my configuration:
    Firefox version: 12
    Selenium version: 2.25
    Language: Java
    Computer: Macintosh
    

    1. Open Terminal
    2. type: /Applications/Firefox.app/Contents/MacOS/firefox-bin -p ( change the path as necessary )
    3. Create a new profile, save it in a directory as you wish..
    4. Start firefox with this profile, add any addons, modifications as you wish.
    5. In Selenium, use:


     FirefoxBinary binary = new FirefoxBinary();  
     File firefoxProfileFolder = new 
     File("/Users/xxx/work/xxx/selenium/src/test/resources/firefoxprofile");
     FirefoxProfile profile = new FirefoxProfile(firefoxProfileFolder);
     profile.setAcceptUntrustedCertificates(true);
     webDriver = new FirefoxDriver(binary, profile);
    

    Again here change the absolute path as required. Add add-ons like autoAuth to pass the HTML Authorization windows in Firefox to this profile..

    这篇关于如何使用Selenium自定义Firefox配置文件? (Java)(并通过HTML授权窗口)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆