0
votes

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

2

2 Answers

0
votes

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);
        }
0
votes

otherwise use PAC file in firefox profile. http://findproxyforurl.com/