1

The following C# is meant to open a selenium driver and connect to a proxy with authentication. The chrome alert pops up on driver.Navigate().GoToUrl(...) and cannot get past. This means I can't deal with the alert in the try{}catch{}.

How can I authenticate the proxy?

The closest I've found so far has been this post

using System;
using System.Net;
using System.Net.Sockets;

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;

namespace ConnectProxy
{
    internal class Program
    {
        private static void Main()
        {

            var proxy = new
            {
                Ip = "XXX",
                Username = "YYY",
                Password = "ZZZ",
                Port = "80"
            };

            string PROXY = proxy.Ip + ":" + proxy.Port;

            Proxy pro = new Proxy();
            pro.HttpProxy = PROXY;
            pro.FtpProxy = PROXY;
            pro.SslProxy = PROXY;

            ChromeOptions options = new ChromeOptions();
            options.Proxy = pro;

            IWebDriver driver = new ChromeDriver(options);
            driver.Navigate().GoToUrl("https://" + proxy.Username + ":" + proxy.Password + "@" + "whatismyipaddress.com/");

            try
            {

                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(15));
                wait.Until(c => c.FindElement(By.Id("content-section")));

                IAlert alert = driver.SwitchTo().Alert();
                alert.SetAuthenticationCredentials(proxy.Username, proxy.Password);
                alert.Accept();
            }
            catch { }
        }
    }
}
Iorek
  • 571
  • 1
  • 13
  • 31

1 Answers1

0

As per selenium documents, attempting to do it through selenium is not an available resource. Instead, as per post, you need to add an extension to chrome with the proxy host and authentication details within it.

Iorek
  • 571
  • 1
  • 13
  • 31