1

facing issue in below question, how to set the proxy settings?

//sample code to add new proxy settings
firefoxProfile.SetPreference(“network.proxy.http_port”, 8080);
1

2 Answers 2

1

Check the code shared in this answer.

//Code copied from the above link
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);

Set PROXY to your proxy server address.

For Java Users

    String PROXY = "proxyserver:9999";
    org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
    proxy.setHttpProxy(PROXY);
    proxy.setFtpProxy(PROXY);
    proxy.setSslProxy(PROXY);

    org.openqa.selenium.remote.DesiredCapabilities cap = org.openqa.selenium.remote.DesiredCapabilities.firefox();
    cap.setCapability(org.openqa.selenium.remote.CapabilityType.PROXY, proxy);

    org.openqa.selenium.WebDriver driver = new org.openqa.selenium.firefox.FirefoxDriver(cap);
Sign up to request clarification or add additional context in comments.

1 Comment

It didn't worked for me, I was using a proxy server and google tells my real ip not the one I am setting in the proxy option. Moreover, In C#, FirefoxProfile class is obsolete. You can use FirefoxOptions.
1

what worked for me: use FirefoxOptions instead of FirefoxProfile:

var options = new FirefoxOptions();
Proxy proxy = new()
{
   HttpProxy = "xxxxxxx"
};
options.Proxy = proxy;
var driver = new FirefoxDriver(options);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.