Home > OS >  configuring Selenium driver to use Socks5 proxy
configuring Selenium driver to use Socks5 proxy

Time:09-22

I'm trying to use my Socks5 proxy while using Selenium web driver here is my code :

        System.setProperty("webdriver.chrome.driver", "dependencies/chromedriver.exe");
        ChromeOptions options = new ChromeOptions();
        Proxy prx =new Proxy() ;
        prx.setSocksVersion(5);
        prx.setSocksProxy("xx.xxx.xxx.xxx:8000");
        prx.setSocksPassword("5xxxxS") ;
        prx.setSocksUsername("VxxxxW") ;
        options.addArguments("--disable-notifications");
        options.addArguments("start-minimized");
        options.setCapability("proxy", prx);
        WebDriver driver = new ChromeDriver(options); // issue here

I'm having the following error :

Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.

CodePudding user response:

You should add proxy server arguments to ChromeOptions:

String host = "shadowsocks6.freeproxy.center";
String port = "8989";
String socks5User = "SOCKS_USER";
String socks5Pass = "SOCKS_Pass";

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--proxy-server=socks5://"   host   ":"   port);
chromeOptions.addArguments("--proxy-auth="   socks5User   ":"   socks5Pass);
WebDriver driver =  new ChromeDriver(chromeOptions);

You can refer to selenium-tiny-projects for complete source code

  • Related