Selenium Webdriver - How to set proxy to “auto-detect” for Firefox

前端 未结 3 1138
自闭症患者
自闭症患者 2021-01-14 04:42

My scripts are running fine on chrome and IE but won\'t start on firefox due to firefox having \"manual\" set for its proxy settings. How can I set this to \"auto-detect\"?<

相关标签:
3条回答
  • 2021-01-14 05:15

    You don't have to set firefox to auto-detect. go to http://wpad/wpad.dat, it will return the javascript file which set up the proxy. You can find the proxy address inside. Then use the following code to do the trick

    FirefoxProfile profile = new FirefoxProfile();
                String PROXY = "xx.xx.xx.xx:8080";
                OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy();
                proxy.HttpProxy=PROXY;
                proxy.FtpProxy=PROXY;
                proxy.SslProxy=PROXY;
                profile.SetProxyPreferences(proxy);
                FirefoxDriver driver = new FirefoxDriver(profile);
    
    0 讨论(0)
  • 2021-01-14 05:32

    Thanks for your help AJ.

    I used the following code to solve my problem:

    FirefoxBinary binary = new FirefoxBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
    FirefoxProfile profile = new FirefoxProfile("C:\\test profile\\");          driver = new FirefoxDriver(binary, profile);
    

    I simply copied the contents of my Mozilla profile to "c:\test profile\". This allowed me to run the test via Selenium but also keep other firefox instances open.

    0 讨论(0)
  • 2021-01-14 05:36

    You only need to add this source to your program:

    FirefoxProfile profile = new FirefoxProfile();
    String PROXY = "your URL WEB proxy:YourPort";
    OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy();
    proxy.HttpProxy = PROXY;
    proxy.FtpProxy = PROXY;
    proxy.SslProxy = PROXY;
    profile.SetProxyPreferences(proxy);
    
    0 讨论(0)
提交回复
热议问题