HTTP proxy in selenium c# works but Socks5 proxy doesn't

64 views Asked by At

I am using selenium c# library and trying to set proxy. when I set HTTP proxy it work, but when I set socks5 proxy it do not work.

Setting HTTP proxy like.

ChromeOptions options = new ChromeOptions();

Proxy proxy = new Proxy();
proxy.Kind = ProxyKind.Manual;
proxy.HttpProxy =
proxy.SslProxy = "server:port";

options.Proxy = proxy;

// setting credentials like

var driverService = ChromeDriverService.CreateDefaultService(applicattionSettings.Settings.ChromeDriverPath);
driverService.HideCommandPromptWindow = true;

var driver = new ChromeDriver(driverService, options);

NetworkAuthenticationHandler handler = new NetworkAuthenticationHandler()
{
        UriMatcher = d => true,
        Credentials = new PasswordCredentials("username", "password")
};

var networkInterceptor = driver.Manage().Network;
networkInterceptor.AddAuthenticationHandler(handler);
networkInterceptor.StartMonitoring();

and it works fine.

Setting socks5 proxy like.

ChromeOptions options = new ChromeOptions();

Proxy proxy = new Proxy();
proxy.Kind = ProxyKind.Manual;

proxy.SocksVersion = 5;
proxy.SocksProxy = "socks5://server:port";
proxy.SocksUserName = "username";
proxy.SocksPassword = "password";

options.Proxy = proxy;

var driverService = ChromeDriverService.CreateDefaultService(applicattionSettings.Settings.ChromeDriverPath);driverService.HideCommandPromptWindow = true;

var driver = new ChromeDriver(driverService, options);

I have also try to set to through AddArguments method but that way we can not pass credentials.

options.AddArguments("--proxy-server=socks5://server:port");

this way at least when I navigate to any website it return ERR_SOCKS_CONNECTION_FAILED error, and when I set it through Proxy class option it simply opens the website without the proxy.

0

There are 0 answers