How to use custom Firefox Profile with Selenium? (Java) (And pass HTML Authorization Window)

后端 未结 3 660
粉色の甜心
粉色の甜心 2020-12-19 09:52

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

相关标签:
3条回答
  • 2020-12-19 10:22

    For Windows, to create a new Firefox Profile, type:

    firefox -profilemanager
    

    in Run that will open the Firefox Profile Manager.

    Let's say you have created a profile called Selenium, then you can use the following code:

    ProfilesIni listProfiles = new ProfilesIni();
    FirefoxProfile profile = listProfiles.getProfile("Selenium");
    WebDriver driver = new FirefoxDriver(profile);
    
    0 讨论(0)
  • 2020-12-19 10:28

    You cannot pass HTML authorization window with Selenium. You have to use Auto IT for this purpose. AutoIT gives you the platform to manage the windows based components. You can invoke AUTO IT scripts from Selenium WebDriver

    0 讨论(0)
  • 2020-12-19 10:31

    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
    Platform: MacOS
    
    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 add-ons, 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..

    0 讨论(0)
提交回复
热议问题