Our network environment using a proxy server to connect to the outside internet, configured in IE => Internet Options => Connections => LAN Settings, like "10.212.20.11:8080".
Now, I'm using selenium webdriver for chrome and IE, but with the proxy server enabled, I can't start the browser.
Here is the python code:
from selenium import webdriver
driver = webdriver.Chrome(executable_path='E:\Selenium\WebDrivers\chromedriver.exe')
Here is the error message(If disable the proxy in IE "Internet Options", it works fine):
Traceback (most recent call last):
File "E:\WorkSpace\GitHub\selenium\sandbox\test.py", line 4, in <module>
driver = webdriver.Chrome(executable_path='E:\Selenium\WebDrivers\chromedriver.exe')
File "C:\Python27\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 66, in __init__
self.quit()
File "C:\Python27\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in quit
self.service.stop()
File "C:\Python27\lib\site-packages\selenium\webdriver\chrome\service.py", line 97, in stop
url_request.urlopen("http://127.0.0.1:%d/shutdown" % self.port)
File "C:\Python27\lib\urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 406, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 519, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 438, in error
result = self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 378, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 625, in http_error_302
return self.parent.open(new, timeout=req.timeout)
File "C:\Python27\lib\urllib2.py", line 406, in open
response = meth(req, response)
File "C:\Python27\lib\urllib2.py", line 519, in http_response
'http', request, response, code, msg, hdrs)
File "C:\Python27\lib\urllib2.py", line 444, in error
return self._call_chain(*args)
File "C:\Python27\lib\urllib2.py", line 378, in _call_chain
result = func(*args)
File "C:\Python27\lib\urllib2.py", line 527, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 401: Unauthorized
So, how to set the proxy for the chromedriver? (IE Driver have the same problem).
Thanks Ehsan, but I changed the code, the error still exists.
from selenium import webdriver
chrome_option = webdriver.ChromeOptions()
chrome_option.add_argument("--proxy-server=10.213.20.62:80" )
driver = webdriver.Chrome(executable_path='E:\Selenium\WebDrivers\chromedriver.exe',
chrome_options=chrome_option)
driver.quit()
Solved! Just in IE => Internet Options => Connections => LAN Settings, add exception address for NOT use proxy "127.0.0.1", this problem solved! Thanks anyway!
Step1: To set proxy in Google Chrome Go to Option (Top-Right Side) > Click on Under the Hood Tab > Click on Change Proxy Settings and you can change Proxy from there.
We can handle proxy in Selenium in Java with the help of PROXY class.
Its possible for Chrome to be started with command lines with selenium web driver. The command line for the proxy is:
--proxy-server=:
I'll save someone from the pain. If you have proxy server that requires you to pass username/pw then it's not possible to pass it through the url itself directly.
I wanted to get it work with Proxymesh so what I did, went to control panel and whitelisted my machine so it wouldn't require username/pw for my computer.
more @ https://github.com/webdriverio/webdriverio/issues/324
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With