Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I opened a browser(any) with selenium tool and applying proxy to that browser by this below posted code, below is for Firefox

    //LINE 1    FirefoxProfile profile = new FirefoxProfile();

    //LINE 2    profile.setPreference("network.proxy.http", configuration
                 .getProxyConfiguration().getHostname());

    //LINE 3    profile.setPreference("network.proxy.http_port", configuration
                 .getProxyConfiguration().getPort());

    //LINE 4    profile.setPreference("network.proxy.type", configuration
                 .getProxyConfiguration().getType().toInt());


    //LINE 5    return new FirefoxDriver(profile); 

Now, I want to apply another proxy configuration for the same browser(Because, If I use another browser, session will be get change, So.... I want to apply my changes to that browser itself). How to apply my proxy configuration to the same browser. When I use same code I've to return driver which uses "NEW". I showed in my code(//LINE 5). Please help me to solve this issue.

Thanks: Ramakrishna K.C

share|improve this question

1 Answer 1

You can create Proxy with Kind = ProxyKind.System

new Proxy { Kind = ProxyKind.System};

Then update the internet settings in the registry

var proxyServer = string.Format("http={0};https={0}", ipAddressAndPort);
        var proxyEnable = enableProxy ? 1 : 0;

        const string subKeyPath = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
        using (var subKey = Registry.CurrentUser.CreateSubKey(subKeyPath)) 
        {
            if (subKey == null)
            {
                throw new Exception(string.Format("Failed to create or open subKey. SubKeyPath: {0} ", subKeyPath));
            }

            subKey.SetValue("ProxyServer", proxyServer, RegistryValueKind.String);
            subKey.SetValue("ProxyEnable", proxyEnable, RegistryValueKind.DWord);
        }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.