Answer the question
In order to leave comments, you need to log in
How to change proxy while working with selenium webdriver chrome?
When working with selenium, I want to change the proxy on the fly for one webdriver without recreating it.
How is it possible to implement this? I can set a proxy before creating a webdriver, but the problem is that:
1) when the webdriver has already been created and I feel like changing the proxy, how can I do this?
2) how to use proxies in selenium, whose authentication goes through username:password?
(note: on the screen, installing proxies before creating webdriver'a)
Answer the question
In order to leave comments, you need to log in
To the second question:
Create a background.js file, substituting your values:
var config = {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: "http",
host: "%proxy_host",
port: parseInt(%proxy_port)
},
bypassList: ["foobar.com"]
}
};
chrome.proxy.settings.set({value: config, scope: "regular"}, function() {});
function callbackFn(details) {
return {
authCredentials: {
username: "%username",
password: "%password"
}
};
}
chrome.webRequest.onAuthRequired.addListener(
callbackFn,
{urls: ["<all_urls>"]},
['blocking']
);
{
"version": "1.0.0",
"manifest_version": 2,
"name": "Chrome Proxy",
"permissions": [
"proxy",
"tabs",
"unlimitedStorage",
"storage",
"<all_urls>",
"webRequest",
"webRequestBlocking"
],
"background": {
"scripts": ["background.js"]
},
"minimum_chrome_version":"22.0.0"
}
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_extension("proxy_auth.zip")
driver = webdriver.Chrome(executable_path='chromedriver.exe', chrome_options=chrome_options)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question