none
Change Google Chrome Proxy Setting Using .Net

    Pertanyaan

  • Hi All,

    I referred reasonable amount of web sites regarding my issue. but still non of the website help me to resolve my issue. according most of website has posted the following code sample. I am using C# with Selenium. Can anyone help to fix this.

    ChromeOptions options = new ChromeOptions();
     
    string proxyUrl = String.Format("http://{0}:{1}@{2}:{3}", "simulation1", "4lN8eLjx1g", "186.227.194.46", "80");
     
    Proxy proxyObj = new Proxy()
    {
        IsAutoDetect = false,
        Kind = ProxyKind.Manual,
        HttpProxy = proxyUrl,
        SslProxy = proxyUrl
    };
     
    options.Proxy = proxyObj;
    options.AddArgument("--proxy-server=" + proxyUrl);
    options.AddArgument("ignore-certificate-errors");
     
    IWebDriver driver = new ChromeDriver(options);
    driver.Navigate().GoToUrl("https://whatismyipaddress.com/");
     
    driver.Close();
    driver.Quit();


    Gehan Fernando Snr. Engineer Technology. AKLO Information Technologies (Pvt) Ltd. #58, 42nd Lane, 5th Floor, Wellawatta, Colombo 06, Sri Lanka. Phone: +94 117 520000 | Mobile: +94 772 269625

    Jumat, 04 Mei 2018 13.00

Semua Balasan

  • Hello,

    According to your question is more related to third party libraries, You could ask from Selenium forum for better support. If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution.

    Best Regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Senin, 07 Mei 2018 08.20
  • Please Following code, this will help you to change the proxy

    First create chrome extension and paste the following java script code.

    Java Script Code

    var Global = {
        currentProxyAouth: {
            username: '',
            password: ''
        }
    }
    
    var userString = navigator.userAgent.split('$PC$');
    if (userString.length > 1) {
        var credential = userString[1];
        var userInfo = credential.split(':');
        if (userInfo.length > 1) {
            Global.currentProxyAouth = {
                username: userInfo[0],
                password: userInfo[1]
            }
        }
    }
    
    chrome.webRequest.onAuthRequired.addListener(
        function(details, callbackFn) {
            console.log('onAuthRequired >>>: ', details, callbackFn);
            callbackFn({
                authCredentials: Global.currentProxyAouth
            });
        }, {
            urls: ["<all_urls>"]
        }, ["asyncBlocking"]);
    
    
    chrome.runtime.onMessage.addListener(
        function(request, sender, sendResponse) {
            console.log('Background recieved a message: ', request);
    
            POPUP_PARAMS = {};
            if (request.command && requestHandler[request.command])
                requestHandler[request.command](request);
        }
    );

    C# Code

     var cService = ChromeDriverService.CreateDefaultService();
        cService.HideCommandPromptWindow = true;
    
        var options = new ChromeOptions();
    
        options.AddArguments("--proxy-server=" + "<< IP Address >>" + ":" + "<< Port Number >>");
        options.AddExtension(@"C:\My Folder\ProxyChanger.crx");
    
        options.Proxy = null;
    
        string userAgent = "<< User Agent Text >>";
    
        options.AddArgument($"--user-agent={userAgent}$PC${"<< User Name >>" + ":" + "<< Password >>"}");
    
        IWebDriver _webDriver = new ChromeDriver(cService, options);
    
        _webDriver.Navigate().GoToUrl("https://whatismyipaddress.com/");


    Gehan Fernando Snr. Engineer Technology. AKLO Information Technologies (Pvt) Ltd. #58, 42nd Lane, 5th Floor, Wellawatta, Colombo 06, Sri Lanka. Phone: +94 117 520000 | Mobile: +94 772 269625

    Minggu, 24 Juni 2018 14.10