Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use authenticated proxy in selenium chromedriver?

After searching for many hours I am starting to think this is impossible.

I need to run Chrome through selenium using different authenticated (not public) proxy's for each run.

PROXY_IP = "<some IP address>" UID = "<the user id>" PWD = "<the password">  options = webdriver.ChromeOptions() options.add_argument("--proxy-server=%s:%s@%s" % (UID,PWD,PROXY_IP))  driver = webdriver.Chrome(executable_path=".\\driver\\chromedriver.exe",                           chrome_options=options) driver.get("<site URL>") 

Chrome will fire-up and display the error:

This webpage is not available ERR_NO_SUPPORTED_PROXIES 

If I use a public proxy requiring no authentication like this...

PROXY_IP = "<public proxy IP address>"  options = webdriver.ChromeOptions() options.add_argument("--proxy-server=%s" % PROXY_IP)  driver = webdriver.Chrome(executable_path=".\\driver\\chromedriver.exe",                           chrome_options=options) driver.get("<site URL>") 

...it runs just fine and displays the site while using the proxy.

I also tried a variant with http:// in front of the user ID:

options.add_argument("--proxy-server=http://%s:%s@%s" % (UID,PWD,PROXY_IP)) 

The fact that I have searched far and wide and haven't found a solution leads me to believe none might exist.

I did find this but I can't make sense out of it:

selenium chromedriver authentication proxy

Not sure what browswermob-proxy is or is supposed to do or how to implement and test in Python. I hate piling up band-aid solutions unless they are absolutely necessary.

EDIT (08NOV21):

I have been away from using Selenium for many years. Because of this I now lack the context (and time, sorry) to go through the newer answers being provided and mark one as the solution to this problem. Does SO have a mechanism one could use to effectively delegate this function to someone who might be a current practitioner with expertise in this domain?

like image 288
martin's Avatar asked May 26 '15 06:05

martin's


People also ask

How does Selenium handle authentication popup in Chrome?

To handle the basic authentication popup, we can pass the username and password along with the web page's URL. When the login pop-up is prompted, we enter the username as “admin” and the password as “admin” and then login. Thus, the user would be successfully logged into the website.


2 Answers

To use proxies with auth in python selenium you can use seleniumwire.

Fistly, install it with pip install selenium-wire

Then import webdriver from seleniumwire instead selenium

from seleniumwire import webdriver options = {     'proxy': {         'http': 'http://username:password@host:port',          'https': 'https://username:password@host:port',         'no_proxy': 'localhost,127.0.0.1' # excludes     } } browser = webdriver.Chrome(path_to_driver, seleniumwire_options=options) 

Now you can use your browser instance exact the same way as selenium: browser.get('https://api.ipify.org') and so on...

like image 97
Blackster Avatar answered Sep 22 '22 07:09

Blackster


I have checked for most of the solutions on the web and for none of them authentication via chrome/firefox desired capabilities is working. Check this link: https://github.com/webdriverio/webdriverio/issues/324. Finally the temporary solution is to whitelist your IP address with the proxy provider.

like image 41
Anurag Narra Avatar answered Sep 22 '22 07:09

Anurag Narra