C # Selenium WebDriver FireFox Profile - Using Authenticated Proxies

When you set the proxy server parameter in the code below, if your proxy server requires authentication, FireFox will display an authentication dialog box and basically you won’t be able to fill it out automatically. So, is there a way to set USERNAME and PASSWORD ?

FirefoxProfile profile = new FirefoxProfile(); String PROXY = "192.168.1.100:8080"; OpenQA.Selenium.Proxy proxy = new OpenQA.Selenium.Proxy(); proxy.HttpProxy=PROXY; proxy.FtpProxy=PROXY; proxy.SslProxy=PROXY; profile.SetProxyPreferences(proxy); FirefoxDriver driver = new FirefoxDriver(profile); 

If you try to format the proxy server line something like this: http://username: pass@192.168.1.1 :8080 You will get an error that the line is not valid. So I think there must be a way to achieve this.

Any help would be appreciated.

+6
source share
3 answers

What you can do is create a profile and save the authentication data in it. If your profile is called "webdriver", you can select it from your code during initialization:

 ProfilesIni allProfiles = new ProfilesIni(); FirefoxProfile profile = allProfiles.getProfile("WebDriver"); profile.setPreferences("foo.bar",23); WebDriver driver = new FirefoxDriver(profile); 
0
source
  String PROXY = "http://login: pass@proxy :port"; ChromeOptions options = new ChromeOptions(); options.AddArguments("user-data-dir=path/in/your/system"); Proxy proxy = new Proxy(); proxy.HttpProxy = PROXY; proxy.SslProxy = PROXY; proxy.FtpProxy = PROXY; options.Proxy = proxy; // Initialize the Chrome Driver using (var driver = new ChromeDriver(options)) 
+2
source

This was with MS UI Automation without AutoIt:

 public void AuthInProxyWindow (string login, string pass) { var proxyWindow = AutomationElement.RootElement .FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ClassNameProperty, "MozillaDialogClass")); var edits = proxyWindow.FindAll(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)); var unamePoint = edits[1].GetClickablePoint(); Mouse.MoveTo(new Point((int) unamePoint.X, (int) unamePoint.Y)); Mouse.Click(MouseButton.Left); SendKeys.SendWait(login); var pwdPoint = edits[2].GetClickablePoint(); Mouse.MoveTo(new Point((int) pwdPoint.X, (int) pwdPoint.Y)); Mouse.Click(MouseButton.Left); SendKeys.SendWait(pass); Keyboard.Press(Key.Return); Logger.Debug("Authefication in Firefox completed succesfully"); } 

Mouse moves Microsoft.TestApi

0
source

Source: https://habr.com/ru/post/924123/


All Articles