Giter VIP home page Giter VIP logo

selenium-proxy-authentication.chrome's Introduction

Selenium Proxy Authentication For Chrome

Easily add your auth proxies to your chrome Driver with one line of code With Extension

Installation

You Can Simply Add this Library to your project with Nuget Package:

Install-Package SeleniumProxyAuthentication.Chrome -Version 2.1.1

Limitations

Currently this library not working in the incognito browser mode

  • i'm working on it and release a new version when it's completed

How to Use it

  • First you need to download the chrome driver from here (make sure that the version of your chrome browser should be match with the version of chrome driver that you download!)
https://chromedriver.chromium.org/downloads
  • Then put the chromedriver.exe in your project directory

  • Create a global chrome option

private static readonly ChromeOptions ChromeOptions = new();
  • Attach your proxy to the chrome option using the extension method that comes with nuget package
ChromeOptions.AddProxyAuthenticationExtension(new SeleniumProxyAuthentication.Proxy(
                    ProxyProtocols.HTTP,
                    "host:port:username:password"
                    ));
  • Cretae chrome driver and use the chrome option
IWebDriver driver = new ChromeDriver(ChromeOptions);
driver.Navigate().GoToUrl(new Uri("https://github.com"));
  • Remove Entire Cache That Created By Extensions (In the Dispose Function)
chromeOptions.DeleteExtensionsCache();

Guides

Proxy Format

  • โœ… Host:Port:Username:Password
  • โœ… Host:Port

Licence

License FOSSA Status

FOSSA Status

selenium-proxy-authentication.chrome's People

Contributors

fossabot avatar mahdibland avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

selenium-proxy-authentication.chrome's Issues

How I can fix this issue using this repo with WinForms app?

Hello:
I found your repo., it seems to be a good one, so I wanted to give it a try.
For using the console app by following the example from here:
https://github.com/mahdibland/Selenium-Proxy-Authentication.Chrome/blob/main/SeleniumProxyAuthentication.Sample/Program.cs
It works.

However, I want to use this repo in WinForms app. So have done the following:

  1. Create a WinForms app project targeting .NET 6.0 (X64 CPU) on Windows 10 (Version 21H2). My IDE is Visual Studio 2022.

  2. Install NUGET packages:
    PM> Install-Package Selenium.Support -Version 4.2.0
    PM> Install-Package Selenium.WebDriver -Version 4.2.0
    PM> Install-Package Selenium.WebDriver.ChromeDriver -Version 102.0.5005.6102
    PM> Install-Package SeleniumProxyAuthentication.Chrome -Version 2.1.1

  3. The following is my C# code trying to do the same as console app.

using OpenQA.Selenium.Chrome;
using SeleniumProxyAuthentication;

namespace SeleniumProxy1Form
{
public partial class Form1 : Form
{

    private static readonly ChromeOptions Chrome_Options = new();

#pragma warning disable CA2211 // Non-constant fields should not be visible
public static ChromeDriver Proxy_Driver;
#pragma warning restore CA2211 // Non-constant fields should not be visible

    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        Chrome_Options.AddProxyAuthenticationExtension(new Proxy(ProxyProtocols.HTTP, 		"proxy_server:proxy_port:proxy_username:proxy_password"));));
    }

    private async void BTNUKProxy_Click(object sender, EventArgs e)
    {
        Proxy_Driver = new(Chrome_Options)
        {
            Url = "http://ip-api.com/json/"
        };
        await Task.Delay(5000);
        Proxy_Driver.Navigate().GoToUrl("https://www.bing.com/");
        Console.Beep();
    }
}

}
But when I run my program, I always get this kind of error:
System.Reflection.TargetInvocationException
HResult=0x80131604
Message=Exception has been thrown by the target of an invocation.
Source=System.Private.CoreLib
StackTrace:
at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)
at Interop.User32.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.Interop.Mso.IMsoComponentManager.FPushMessageLoop(UIntPtr dwComponentID, msoloop uReason, Void* pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(msoloop reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(msoloop reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at SeleniumProxy1Form.Program.Main() in C:\Selenium\SeleniumProxy1Form\SeleniumProxy1Form\Program.cs:line 14

This exception was originally thrown at this call stack:
Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(string, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, System.IO.FileOptions)
Microsoft.Win32.SafeHandles.SafeFileHandle.Open(string, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, System.IO.FileOptions, long)
System.IO.Strategies.OSFileStreamStrategy.OSFileStreamStrategy(string, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, System.IO.FileOptions, long)
System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(string, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, System.IO.FileOptions, long)
System.IO.Strategies.FileStreamHelpers.ChooseStrategy(System.IO.FileStream, string, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, int, System.IO.FileOptions, long)
System.IO.FileStream.FileStream(string, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, int, bool)
System.IO.Compression.ZipFileExtensions.DoCreateEntryFromFile(System.IO.Compression.ZipArchive, string, string, System.IO.Compression.CompressionLevel?)
System.IO.Compression.ZipFile.DoCreateFromDirectory(string, string, System.IO.Compression.CompressionLevel?, bool, System.Text.Encoding)
System.IO.Compression.ZipFile.CreateFromDirectory(string, string)
SeleniumProxyAuthentication.Utilities..cctor.AnonymousMethod__9_5(string, string)
...
[Call Stack Truncated]

Inner Exception 1:
IOException: The process cannot access the file 'C:\Users\John\AppData\Roaming\ProxyAuthCache\4.3.1.1796950237348\Details\manifest.json' because it is being used by another process.

By the way, the following C# code works for console app project.

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;

namespace SeleniumProxyAuthentication.Sample
{
public class Program
{
private static readonly ChromeOptions Chrome_Options = new();

    static void Main()
    {
        Chrome_Options.AddProxyAuthenticationExtension(new Proxy(ProxyProtocols.HTTP, 		"proxy_server:proxy_port:proxy_username:proxy_password"));));
        IWebDriver driver = new ChromeDriver(Chrome_Options);
        driver.Navigate().GoToUrl(new Uri("http://ip-api.com/json/"));
        Console.WriteLine("Done!");
        Console.Beep();
    }
}

}

I was thinking that my console project is using the json file, but I stop the console project, and change different proxy, or I even reboot my PC. But I still get the same error, but the console app project always works.
Please let me know how I can fix this issue, why it happens only for WinForms app?
Thanks,

assembly

Hello, If i input code, I got error

Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.