How to handle proxy setting using selenium Webdriver?

 In this article, i will talk about How to handle proxy setting using selenium Webdriver?
Suggested Article to read: What is Firefox profile, Need of Firefox profile?

If we try to access some secure application, we get proxy related error many times and manually we need to update the proxy there. But what if we are automating that secure application? Our automation code should handle this.

Some applications have also issues related to SSL certification error. We again do that manually by accepting & confirming the certificate. But again, what if this encounter when we automate application using selenium Webdriver?
In this post, let’s talk about how to handle proxy setting using selenium Webdriver?
While setting up the proxy, note that there are different values for network.proxy.type , which we need to set based on our need. Here are some values –
0 – Direct connection (or) no proxy.
1 – Manual proxy configuration
2 – Proxy auto-configuration (PAC).
4 – Auto-detect proxy settings.
5 – Use system proxy settings.
Below 4 steps explain how can we handle proxy setting via selenium
Step1: Create the FirefoxProfile object.
Step2: Set preference for network.proxy.type
Step3: Set preference for network.proxy.http
Step4: network.proxy.http_port
    FirefoxProfile profile = new FirefoxProfile();

    profile.setPreference("network.proxy.type", 1);

    profile.setPreference("network.proxy.http", "");

    profile.setPreference("network.proxy.http_port", 8080);

    profile.setPreference("network.proxy.ssl", "");

    profile.setPreference("network.proxy.ssl_port", 8080);

    WebDriver driver = new FirefoxDriver(profile);

That’s it, this should handle the updated proxy in code.

Hope this helps. Drop your comments.

Leave Comment

Your email address will not be published. Required fields are marked *

Looking for learning Framework Development from Scratch? Lookout for Detailed Framework Development videos on YouTube here -

Get the Framework code at Github Repo: