0

I am trying to connect to a website through a proxy with Selenium in C#. The following code successfully loads the proxy:

var options = new ChromeOptions();
string proxyHost = "proxy";
int proxyPort = proxy;
string proxyUser = "proxy";
string proxyPassword = "proxy[enter image description here][1]";

options.AddArgument("--proxy-server=http://" + proxyHost + ":" + proxyPort);
options.AddArgument("--proxy-auth=" + proxyUser + ":" + proxyPassword);

var driver = new ChromeDriver(options);

driver.Navigate().GoToUrl("https://whatismyipaddress.com/"); 

However, when prompted for the proxy username and password, I am unsure how to input them in the Selenium code. What code do I need to include in C# to input the proxy username and password?

ggeorge
  • 1,496
  • 2
  • 13
  • 19
MSBB
  • 1
  • 1
  • This question isn't about using the Visual Studio application, so I've removed that tag for you. – ProgrammingLlama Jun 16 '23 at 16:26
  • I found this answer, but I don't know if it works for you so I won't mark your question a duplicate of this one: https://stackoverflow.com/a/27740556/3181933 – ProgrammingLlama Jun 16 '23 at 16:28
  • And another question that seems potentially promising: https://stackoverflow.com/questions/26676658/how-to-authenticate-user-password-proxy-in-c-sharp-selenium-chrome-driver – ProgrammingLlama Jun 16 '23 at 16:29
  • still have the same problem, i used code from this links, i update my code and you see, i can add screen from google what i got – MSBB Jun 16 '23 at 16:37
  • Well, it's always a good idea to show what research you've done and attempts you've made to fix a problem. I wasn't aware you had already tried these approaches because you didn't mention having tried them. I would recommend editing your question to clarify what you have and haven't tried so that others don't provide you with things you have already tried. – ProgrammingLlama Jun 16 '23 at 16:39
  • now, i edited my post – MSBB Jun 16 '23 at 16:39
  • Re your edit: I don't see any answer from either of those links suggesting `--proxy-auth=username:password`. Can you advise where you're getting that from and clarify if you have actually tried any of the solutions in the two questions I linked you to. – ProgrammingLlama Jun 16 '23 at 16:40

1 Answers1

0

You can use a NuGet package to fix that issue, I use it before it works fine : Proxy Extension

Usage :

using OpenQA.Selenium.Chrome.ChromeDriverExtensions;

ChromeOptions options = new ChromeOptions();
options.AddHttpProxy(proxy_ip, Convert.ToInt32(port), proxy_user, proxy_pass);
driver = new ChromeDriver(options);