4

I have used DesiredCapabilities

capabilities = dict(DesiredCapabilities.CHROME)
capabilities['proxy'] = {'proxyType': 'MANUAL',
                         'httpProxy': proxy['address'],
                         'ftpProxy': proxy['address'],
                         'sslProxy': proxy['address'],
                         'noProxy': '',
                         'class': "org.openqa.selenium.Proxy",
                         'autodetect': False
                         }
chrome_options = Options()
chrome_options.add_argument('--headless')

But nothing happen, where if I remove headless I get to see Authentication required alert.

I have also used

chrome_options.add_argument('--proxy-server=http://%s:%s@%s:%s'%(Config.PROXY_USERNAME,Config.PROXY_PASSWORD,Config.PROXY_URL,Config.PROXY_PORT))

But this did not help. Where I have changed "http" to "socks","socks4" and "socks5" where this didn't help even.

Mohit Tamta
  • 53
  • 1
  • 5
  • I forgot to mention that, username and password is also there with DesiredCapabilities proxy = {'address': '%s:%s'%(Config.PROXY_URL,Config.PROXY_PORT), 'username': Config.PROXY_USERNAME, 'password': Config.PROXY_PASSWORD} capabilities['proxy']['socksUsername'] = proxy['username'] capabilities['proxy']['socksPassword'] = proxy['password'] – Mohit Tamta Jan 24 '18 at 16:41
  • Update the question with this information for a better analysis. – undetected Selenium Jan 24 '18 at 16:51
  • i am facing this issue. @MohitTamta are there updates on this? – Mans Jun 06 '18 at 14:14

1 Answers1

0

Unfortunately, headless chrome discards alerts (Issue 718235) and extensions are not supported (Issue 706008) so we can't use the tricks which work in GUI mode. This leaves us with two main options:

Option 1 - Proxy redirect

Run a separate proxy without authentication and redirect it to the target proxy with authentication.

You can do it in one line with mitmproxy:
mitmproxy --mode upstream:http://<target-proxy-ip>:<target-proxy-port> --upstream-auth <user>:<password> -p 3128 and configure your client to use localhost:3128 as a proxy.

You can install mitmproxy via pip: pip install mitmproxy (requires python3)
Reference: https://docs.mitmproxy.org/stable/overview-installation/

Or with Squid proxy: Squid: forward to another proxy (with authentication details for the parent proxy)

Option 2 - Use Xvfb display server

Xvfb performs all graphical operations in virtual memory without showing any screen output
Reference: https://www.x.org/releases/X11R7.7/doc/man/man1/Xvfb.1.xhtml

Here is the instruction for using it with Selenium: How do I run Selenium in Xvfb?
Python wrapper for Xvfb: https://github.com/ponty/pyvirtualdisplay

Good luck!

AI Mechanic
  • 631
  • 7
  • 8